重置为jquery datatable中的默认排序

时间:2014-04-03 13:27:53

标签: sorting datatable default

我有一个页面,其中一个下拉列表为Report1和Report2。如果我选择Report1,它将填充startdate和enddate。我将选择startdate和end date然后cliick on view报告它将执行ajax调用并获取数据并显示在表中,我正在使用数据表。

我有第二个库存的默认排序,我也可以对其他列进行排序。如果我对其他列进行排序,然后选择其他报告Report2,然后选择startdate adn end date,然后点击查看报告按钮。再次如果我选择Report1和startdate和end date并点击查看报告按钮,它将对另一列进行排序,但不对默认排序列进行排序。任何帮助都会很明显。

以下是我的代码

$('#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';
                }

2 个答案:

答案 0 :(得分:1)

请使用这种方式:

counts = dict()

for word in x:                                  # x is file named "f2.txt"
    words = word.split()
    print words
    counts[words] = counts.get(words,0) + 1
print counts 

答案 1 :(得分:0)

如果我理解正确你想要一个会返回默认顺序的函数吗?如果是这种情况,我认为以下内容将有所帮助:

http://datatables.net/plug-ins/api/fnSortNeutral