如何让jQuery Tablesorter默认排序降序? [英] How to get jQuery Tablesorter to sort descending by default?

查看:311
本文介绍了如何让jQuery Tablesorter默认排序降序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚这一点。这个问题也在这里被问到 http://www.nabble.com/TableSorter-plugin---default-column-sort-DESC-instead--How--to25180761s27240.html#a25180761 没有回复。

I can't figure this out. This question was also asked here http://www.nabble.com/TableSorter-plugin---default-column-sort-DESC-instead--How--to25180761s27240.html#a25180761 with no response.

我试过了

    $.tablesorter.defaults.sortInitialOrder = 'desc';

并将jquery.tablesorter.js文件更改为默认为'desc'但它不起作用。当我单击列标题时,第一个排序仍然是升序,因此用户必须单击两次才能下降值。

and altering the jquery.tablesorter.js file to default to 'desc' but it doesn't work. When I click on the column headers, the first sort is still ascending so the user has to click twice to descend the values.

如何让Tablesorter按降序排序默认情况下?

How can I get Tablesorter to sort by descending by default?

推荐答案

看起来像tableorter代码中的错误,或者我误解了sortInitialOrder参数应该做什么。在第536行,它通过查看列已排序的次数并采用值mod 2来设置分拣机顺序。它还应考虑sortInitialOrder的值。

Looks like a bug in the tablesorter code, or I'm misunderstanding what the sortInitialOrder parameter is supposed to do. At line 536 it sets the sorter order by looking at the number of times the column has been sorted and taking the value mod 2. It should also take into account the value of sortInitialOrder.

更改第536行

this.order = this.count++ % 2;

this.order = this.count++ == 0 ? this.order : (1 - this.order);

并在此行后添加(以便第一次点击其他列时为您提供默认值)

And add after this line (so that the first click on a different column gives you the default)

$headers.not($cell).each( function() {
    this.count = 0;
});

并从

o.count = s[1];

o.order = o.count = s[1];

以便在应用sortList时覆盖初始订单。

so that the initial order is overridden if a sortList is applied.

然后,您可以使用sortInitialOrder参数对tablesorter设置列的默认第一个排序顺序。 sortList中提供的任何排序都将覆盖为整个表提供的sortInitialOrder。

Then you can use the sortInitialOrder parameter to tablesorter to set up a default first sort order for the column. Any ordering provided in the sortList will override the sortInitialOrder provided for the entire table.

请注意,这适用于Tablesorter 2.0。

Note that this applies to Tablesorter 2.0.

这篇关于如何让jQuery Tablesorter默认排序降序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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