Adding Column (Client Side) to Server Side DataTable
Adding Column (Client Side) to Server Side DataTable
I have a table which reads database columns from a database and just displays it as is column for column. However on the display side I need to inject a (calculated column) at column index 3. I can do this by adding it to the html header and adding the data to the server side output that feeds the table. However I am having problems with the server side sorting as now the server side code does not know about this column.
Is there a way I can tell Datatables either to not allow sorting of that "fake" column. I am probably not doing something the proper way here lol
here is my js
[code]
var oTable = $('#fbcreditlog').dataTable( {
"bProcessing": true,
"bFilter": false,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "/admin/pstoolfbcreditajax/?start_date="+default_start_date+"&end_date="+default_end_date,
"aaSorting": [[ 1, "desc" ]],
"oLanguage": {
"sZeroRecords": "No transactions found."
},
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "/admin-assets/TableTools.swf",
"aButtons": [
"copy", "print",
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
},
"fnServerData": function( sSource, aoData, fnCallback) {
$.getJSON(sSource, aoData, function(json) {
if(jQuery.isEmptyObject(json)) location.href = '/admin/login/';
else fnCallback(json);
});
},
} );
[/code]
here is my html
[code]
Order ID
Buyer Facebook ID
Credits
Dollar Amount
Description
Bundle ID
Status
Transaction Date
Loading data from server
[/code]
and here is the output from my server side script
[code]
{"sEcho":1,"iTotalRecords":"2","iTotalDisplayRecords":"2","aaData":[["23453453323","100002497224420","30","3","3000 Coins for 30 Facebook Credi","1","placed","2011-11-21 13:41:58"],["56745467456","100002497224420","20","2","2000 Coins for 20 Facebook Credi","1","placed","2011-11-18 13:41:58"]]}
[/code]
Is there a way I can tell Datatables either to not allow sorting of that "fake" column. I am probably not doing something the proper way here lol
here is my js
[code]
var oTable = $('#fbcreditlog').dataTable( {
"bProcessing": true,
"bFilter": false,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "/admin/pstoolfbcreditajax/?start_date="+default_start_date+"&end_date="+default_end_date,
"aaSorting": [[ 1, "desc" ]],
"oLanguage": {
"sZeroRecords": "No transactions found."
},
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "/admin-assets/TableTools.swf",
"aButtons": [
"copy", "print",
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
},
"fnServerData": function( sSource, aoData, fnCallback) {
$.getJSON(sSource, aoData, function(json) {
if(jQuery.isEmptyObject(json)) location.href = '/admin/login/';
else fnCallback(json);
});
},
} );
[/code]
here is my html
[code]
Order ID
Buyer Facebook ID
Credits
Dollar Amount
Description
Bundle ID
Status
Transaction Date
Loading data from server
[/code]
and here is the output from my server side script
[code]
{"sEcho":1,"iTotalRecords":"2","iTotalDisplayRecords":"2","aaData":[["23453453323","100002497224420","30","3","3000 Coins for 30 Facebook Credi","1","placed","2011-11-21 13:41:58"],["56745467456","100002497224420","20","2","2000 Coins for 20 Facebook Credi","1","placed","2011-11-18 13:41:58"]]}
[/code]
This discussion has been closed.
Replies
Just wondering if there is a way to make the datatable ignore the column when doing the index counts or how I could work around this with a sorting callback or something of that nature.
You can set bSortable: false in aoColumns/aoColumnDefs for that column (and bSearchable: false if you want)
Thanks for the tip on the server side bit.