Datatable pagination
Im currently trying to find a way to have pagination in my datatable. Im using the http://www.datatables.net/ plugin and i managed to get some json data in the table however is their a way to put the data that went through the crossfilter in my datatable ?
Im currently retrieving json data through server side code and i put the result of this request in my datatable however this is all the data. Not the actual filtered data that is stored in the crossfilter data.
Thanks in advance !
Have you tried using datatable programmatically after calling dc.renderAll though since I have never tried myself not sure how it will work when table is filtered by other dimensions.
Btw, I believe it can certainly be done using d3 and crossfilter though just not sure if you can do it with some 3rd party table plugin.
I managed to get it working by using the datatables plugin. I basically created a group which returns all records ordered by the connection dimension ==> this can be any dimension. I then used the alldata as input in my datatable.
alldata = connection.top(Infinity);
The only thing left to do is create a function that would redraw the datatable:
function RefreshTable(alldata) {
datatable.fnClearTable();
datatable.fnAddData(alldata);
datatable.fnDraw();
}
I then called the function refreshtable in everychart. .on("filtered", function (chart) { dc.events.trigger(function () { alldata = connection.top(Infinity); RefreshTable(alldata); });
Hi, I know not very good practice to reopen an issue, but do you have a full example of this so I can see exactly how this works?
I have been trying to integrate the datatables plugin using the DOM but it has a crisis over the fact that it can't find a full table to work with as dc.js doesn't produce a data table with a <table> or <thead> tag.
@jonscrut I added the following html below to my page, in javascript i do the following:
<table class="table table-hover dc-data-table">
<thead>
<tr class="header">
<th>CallID</th>
<th>Connection</th>
<th>StartTime</th>
<th>EndTime</th>
<th>QueryTime</th>
<th>Profile</th>
<th>Object</th>
<th>Method</th>
<th>Error</th>
<th>ResultLink</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
</tfoot>
datatable = $(".dc-data-table").dataTable({
"sDom": 'T<"clear"><"H"lr>t<"F"ip>',
"oTableTools": {
"aButtons": [
"copy", "csv", "xls"
]
},
"aaData": methoddimchart.top(2000),
"bDestroy": true,
"aoColumns": [
{
"fnRender": function (oObj) {
return "<a href='DetailCall.aspx?CallID=" + oObj.aData[0] + "' target='_blank'><img
src='img/empty.png' style='height: 35px; width: 35px;' title='" + oObj.aData[0] + "' alt='"
+ oObj.aData[0] + "' /></a>";
}
},
"sName": "ID", "bSortable": false
},
{
"fnRender": function (oObj) {
return "<a href='DetailConnection.aspx?ConnectionID=" + oObj.aData[2] + "'>" +
oObj.aData[1] + "</a>";
}
,
"sName": "Connection", "bSortable": true
},
{
"fnRender": function (oObj) {
return oObj.aData[4];
}
,
"sName": "StartTime", "bSortable": true
},
{
"fnRender": function (oObj) {
return oObj.aData[5];
}
,
"sName": "EndTime", "bSortable": true
},
{
"fnRender": function (oObj) {
return oObj.aData[6];
}
, "sName": "QueryTime", "bSortable": true
},
{
"fnRender": function (oObj) {
return oObj.aData[8];
}
,
"sName": "Profile", "bSortable": true
},
{
"fnRender": function (oObj) {
return oObj.aData[9];
}
,
"sName": "Object", "bSortable": true
},
{
"fnRender": function (oObj) {
return oObj.aData[10];
}
,
"sName": "Method", "bSortable": true
}, {
"fnRender": function (oObj) {
return oObj.aData[11];
}
,
"sName": "Error", "bSortable": true
},
{
"fnRender": function (oObj) {
return oObj.aData[14];
}
,
"sName": "ResultLink", "bSortable": true
},
]
});
I get the data from my dimension methoddimchart and i do top(2000) which basically means it will select the top 2000 rows. The dimension can be anything doesn't really matter which one you choose just make sure you can access it out your "main" function.
Now this will only display the data but if you filter in some charts the data isn't updated in the datatable which is normal behaviour because datatable doesn't automatically trigger a refresh. So you have to make a refresh yourself.
So basically everytime one of my charts is filtered i do the following to update my data.
function RefreshTable2() {
datatable.fnClearTable();
datatable.fnAddData(methoddimchart.top(2000));
datatable.fnDraw();
}
Thanks! I got on the right track in the end. I'm using a csv as input but it looks to me as you are suing some serverside stuff? Anyway, this is what worked for me in getting the table showing.
The key is to have the same number of header columns as you are identifying in the datatables aoColumns definition and to use mdata instead of sname. Also, datatables doesn't like null values, so good to set that for each column too ("sDefaultContent": " ")
Haven't tried the updating yet...
This went in the div for displaying the table:
`
Export Country
Export Country Code
Import Country
Import Country Code
FH rating
TIV value
Year
`
And this went in the dc script
datatable = $(".dc-data-table").dataTable({
"bDeferRender": true,
"aaData": allCsvData.top(Infinity),
"bDestroy": true,
"aoColumns": [
{ "mData": "exportcountry", "sDefaultContent": " " },
{ "mData": "exportccode", "sDefaultContent": " " },
{ "mData": "importcountry", "sDefaultContent": " " },
{ "mData": "importccode", "sDefaultContent": " " },
{ "mData": "fh_rating_abc", "sDefaultContent": " " },
{ "mData": "tiv_value", "sDefaultContent": " " },
{ "mData": "year", "sDefaultContent": " " }
]
});