在jquery datatable中重置为默认排序 [英] reset to default sorting in jquery datatable
问题描述
我有第二个coulmn的默认排序,我也可以排序其他列。如果我对其他列进行排序,然后选择其他报表Report2,然后选择startdate adn结束日期,然后点击查看报告按钮。再次如果我选择Report1,开始日期和结束日期并点击视图报告按钮,它排序其他列,但不排序默认排序列。任何帮助都是可以理解的。
以下是我的代码
$ ('#userTable')。dataTable({
bProcessing:false,
bServerSide:false,
bFilter:false,
bSearchable
oLanguage:{
sZeroRecords:找不到活动用户,
sInfo:找到的总记录:_TOTAL_
},
aaSorting:[[2,asc]],
aoColumnDefs:[{
mData:emailAddr,
sWidth:20%,
aTargets:[0]
},{
mData:null,
sWidth:20%,
mRende r:function(data,type,row){
return row.firstNm +''+ row.lastNm;
},
bSortable:false,
aTargets:[1]
},{
mData:retailerId,
sWidth:20%,
aTargets:[2]
},{
mData:role,
sWidth:20%
aTargets:[3]
},{
mData:contactPhone,
bSortable:false,
sWidth 20%,
aTargets:[4]
}],
fnInfoCallback:function(oSettings,iStart,iEnd,iMax,iTotal,sPre){
返回'显示'+ iStart +'到'+ iEnd +'+ iTotal +'条目'
}
请使用这种方式: / p>
var DTable = $(< your table>)。dataTable({
...
..
}
setInterval(function(){
DTable.fnClearTable(0);
DTable.fnSort([0,desc]);
DTable.fnDraw();
},5000);
I have a page on which one dropdown as Report1 and Report2 is there. If I select Report1 it will populate startdate and enddate. I will select startdate and end date then cliick on view report it will do ajax call and fetch the data and displaying in table, I am using datatable for this.
I have default sorting of the second coulmn and also I can able to sort other column. If I sort other column and then select the other report Report2 and then select startdate adn end date and then hit the view report button. Again If I select the Report1 and startdate and end date and hit the view report button, it is sorting the other column but not the default sorting column. Any help would be appreciable.
Below is my code
$('#userTable').dataTable({
"bProcessing" : false,
"bServerSide" : false,
"bFilter" : false,
"bSearchable" : false,
"oLanguage" : {
"sZeroRecords" : "No Active Users Found",
"sInfo" : "Total Records Found: _TOTAL_ "
},
"aaSorting" : [ [ 2, "asc" ] ],
"aoColumnDefs" : [ {
"mData" : "emailAddr",
"sWidth" : "20%",
"aTargets" : [ 0 ]
}, {
"mData" : null,
"sWidth" : "20%",
"mRender" : function(data, type, row) {
return row.firstNm + ' ' + row.lastNm;
},
"bSortable" : false,
"aTargets" : [ 1 ]
}, {
"mData" : "retailerId",
"sWidth" : "20%",
"aTargets" : [ 2 ]
}, {
"mData" : "role",
"sWidth" : "20%",
"aTargets" : [ 3 ]
}, {
"mData" : "contactPhone",
"bSortable" : false,
"sWidth" : "20%",
"aTargets" : [ 4 ]
} ],
"fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
return 'Displaying '+iStart+' to '+iEnd+' of ' +iTotal + ' entries';
}
Please use this way:
var DTable = $("<your table>").dataTable ({
...
..
}
setInterval( function () {
DTable.fnClearTable( 0 );
DTable.fnSort( [ 0, "desc" ] );
DTable.fnDraw();
}, 5000 );
这篇关于在jquery datatable中重置为默认排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!