I am using jquery datatables and I need to sort data by the first column which contains checkboxes by displaying checked boxes first
oTable = $('#userTable', context).dataTable(
{
"sAjaxSource":'/ajax/getdata/',
"fnServerData": function ( sSource, aoData, fnCallback, oSettings )
{
oSettings.jqXHR = $.ajax(
{
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": params,
"success" : function(data)
{
fnCallback(data);
fnSortBySelected();
}
});
}
});
var fnSortBySelected = function()
{
var oSettings = oTable.fnSettings();
var i = 0;
$('td:first-child input[type=checkbox]',oTable).sort(function(a, b)
{
if(a.checked)
oTable.fnUpdate( oSettings.aoData[i]._aData, i, 0);
else
oTable.fnUpdate( oSettings.aoData[i+1]._aData, i, 0);
i++;
});
}
thanks for your time , this is what i tried so far :
oTable = $('#userTable', context).dataTable({
"sAjaxSource":'/ajax/getdata/',
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": params,
"success" : function(data){
fnCallback(data);
fnSortBySelected();
}
} );
}
});
var fnSortBySelected = function()
{
var oSettings = oTable.fnSettings();
var i = 0;
$('td:first-child input[type=checkbox]',oTable).sort(function(a, b){
if(a.checked)
oTable.fnUpdate( oSettings.aoData[i]._aData, i, 0);
else
oTable.fnUpdate( oSettings.aoData[i+1]._aData, i, 0);
i++;
} );
}
I Made it using Snickers answer by creating a hidden column (first column index 0) on every selected checkbox , i set the corresponding hidden column to “selected” then I sort the table on that hidden column and first name column
to hide the first column use
for every clicked checkbox do this
and then call
Thank you guys for your help