我正在使用 jquery 数据表,我需要通过首先显示复选框来按包含复选框的第一列对数据进行排序
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++;
});
}
感谢您的时间,这是我到目前为止所尝试的:
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++;
} );
}