2017-10-20 38 views
2

我有一个站点正在做NHL的排名。我有一个表格中的排名,并使用jQuery Datatables进行排序和筛选。在jQuery数据表的过滤器上重置排序

我想要的是当有人改变原来的排序过滤器来重置。因此,我有一份订单,旨在根据领带破坏者显示球队的秩序。当某人按Wins排序时,然后更改他们正在查看的会议或部门,我希望它重置为原始排序,现在它保持Wins的顺序。

我试过几种方法,但他们都没有做任何事情。思考?

下面的代码是过滤功能。哪一个涉及哪个会议或部门。我已经在很多地方尝试过了,但没有任何影响。

if(whichType == "conference") { 
    $(".standings-type").html(whichOne) 
    standings 
    .columns([12, 11]) // columns holding type and name of division/conference 
    .search("") // reset the table to have all teams 
    .column(12) // the column that holds the conference names 
    .search(whichOne) //searches for the name based on a variable. 
    .order([0, "desc"]) // <<< want to resort by column 0, does not work 
    .draw(); 
} 

回答

1

尝试下面的代码:

standings 
    .columns([12, 11]) // columns holding type and name of division/conference 
    .search(""); // reset the table to have all teams 

standings 
    .column(12) // the column that holds the conference names 
    .search(whichOne); //searches for the name based on a variable. 

standings 
    .order([0, "desc"]) 
    .draw(); 
+0

奇怪的是,我不得不说分裂成两个电话,说实话这种解决方案甚至从来没有穿过我的脑海,但它的工作正是我想要的。非常感谢你! –

+0

@RickCalder,尽管这似乎没有记录,但并不是所有的API调用都可以链接。例如,它包括以“column()”或“columns()'开始的方法。我还会在上面拆分两个'column()'调用,但它的工作原理只是因为你使用了相同的子集(索引为'12'的列)。 –

+0

非常感谢,我是数据表的新手,在未来的故障排除中,您的答案为我提供了一个新的考虑事项! –