I like to use JQuery datatables for this: http://datatables.net/
First add the table and the header row:
<table id="dc-data-table" class="list table table-striped table-bordered">
<thead>
<tr>
<th>Country</th>
<th>Users</th>
</tr>
</thead>
</table>
Next build your dimensions like normal:
var ndx = crossfilter(data),
countryDimension = ndx.dimension(function (d) {
return d.country;
}),
Then bind the jquery data table:
var datatable = $("#dc-data-table").dataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": false,
"bAutoWidth": false,
"bDeferRender": true,
"aaData": countryDimension.top(Infinity),
"bDestroy": true,
"aoColumns": [
{ "mData": "country", "sDefaultContent": ""},
{ "mData": "users", "sDefaultContent": " " }
]
});
Finally, hook it into dc.js if you want the table to reflect the filters of your other charts:
function RefreshTable() {
dc.events.trigger(function () {
alldata = countryDimension.top(Infinity);
datatable.fnClearTable();
datatable.fnAddData(alldata);
datatable.fnDraw();
});
}
for (var i = 0; i < dc.chartRegistry.list().length; i++) {
var chartI = dc.chartRegistry.list()[i];
chartI.on("filtered", RefreshTable);
}
Here is a jsFiddle that demonstrates this: http://jsfiddle.net/djmartin_umich/d55My/