sort by checkbox columns doesn't work
sort by checkbox columns doesn't work
coolpal
Posts: 2Questions: 0Answers: 0
I have come across this wonderful plugin just last week and I am trying to build a DataTable using javascript array (returned from server via ajax call). The last column in the table is rendered as a checkbox and I tried to incorporate the sorting extention based on "DataTables live DOM sorting example" from here: http://datatables.net/examples/plug-ins/dom_sort.html
In my case, that doesn't seem to affect anything when I sort by the checkbox column. I tried reviewing what the custom sort data function is returning and it seems to be fine. Even tried the function to return numeric array and changed the sType to numeric, which seems to alter the table but the sorting is all wonky (it sorts at random).
here's the snippets of code I am trying.
[code]
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
{
var aData = [];
$( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( this.checked==true ? "1" : "0" );
} );
alert(aData);
return aData;
}
oTable = $('#table1').dataTable( {
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"fnInitComplete": function() {
this.fnAdjustColumnSizing();
//$(".dataTables_wrapper").css("width", $("#table1").css("width"));
},
"bDeferRender": false,
"aoColumns": [
{ "mDataProp": "geid", "sTitle": "Geid",
"mRender": function ( data, type, full ) {
return ''+ data +'';
}
},
{ "mDataProp": "deptId", "sTitle": "Department Id" },
{ "mDataProp": "firstName", "sTitle": "First Name" },
{ "mDataProp": "lastName", "sTitle": "Last Name" },
{ "mDataProp": "emailAddress", "sTitle": "Email Id"}, //, "sClass": "wrapword2" },
{ "mDataProp": "selected", "sTitle": "Select",
"mRender": function ( data, type, full ) {
return '';
},
"sSortDataType": "dom-checkbox"
}
],
"aaData": resultArr,
"aaSorting": [[3, 'asc']]
});
[/code]
Any help is greatly appreciated.
In my case, that doesn't seem to affect anything when I sort by the checkbox column. I tried reviewing what the custom sort data function is returning and it seems to be fine. Even tried the function to return numeric array and changed the sType to numeric, which seems to alter the table but the sorting is all wonky (it sorts at random).
here's the snippets of code I am trying.
[code]
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
{
var aData = [];
$( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( this.checked==true ? "1" : "0" );
} );
alert(aData);
return aData;
}
oTable = $('#table1').dataTable( {
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"fnInitComplete": function() {
this.fnAdjustColumnSizing();
//$(".dataTables_wrapper").css("width", $("#table1").css("width"));
},
"bDeferRender": false,
"aoColumns": [
{ "mDataProp": "geid", "sTitle": "Geid",
"mRender": function ( data, type, full ) {
return ''+ data +'';
}
},
{ "mDataProp": "deptId", "sTitle": "Department Id" },
{ "mDataProp": "firstName", "sTitle": "First Name" },
{ "mDataProp": "lastName", "sTitle": "Last Name" },
{ "mDataProp": "emailAddress", "sTitle": "Email Id"}, //, "sClass": "wrapword2" },
{ "mDataProp": "selected", "sTitle": "Select",
"mRender": function ( data, type, full ) {
return '';
},
"sSortDataType": "dom-checkbox"
}
],
"aaData": resultArr,
"aaSorting": [[3, 'asc']]
});
[/code]
Any help is greatly appreciated.
This discussion has been closed.
Replies
[code]
function (data, type, full) {
if (type === 'display') {
// for display/render purposes, create a checkbox.
return '';
}
// for sorting purposes, return the actual data.
return data;
}
[/code]
I was able to figure this out using Allen's response found here: http://datatables.net/forums/discussion/12063/mdata-mrender-and-ordering/p1