在jquery datatable中重置为默认排序 [英] reset to default sorting in jquery datatable

查看:1536
本文介绍了在jquery datatable中重置为默认排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中一个下拉列表为Report1和Report2。如果我选择Report1,它将填充startdate和enddate。我将选择startdate和结束日期,然后cliick在视图报告它将做ajax调用并获取数据和显示在表中,我使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆