jquery tablesorter2:如何对生成的Dropdown的内容进行排序
jquery tablesorter2: How to sort the content of the generated Dropdown
我将 jquery tablesorter2 (https://mottie.github.io/tablesorter/docs/index.html) 与过滤器小部件一起使用。
现在我想将生成的下拉列表中值的排序顺序(不是 table-值)从 asc 更改为 desc。
我为此制作了一个 jsFiddle:
在这里您可以找到折扣栏。我想让它的值按降序排列,这样最大的折扣就出现在下拉列表的第一位。
有一些选项,但似乎没有合适的:
// each option has an associated function that returns a boolean
// function variables:
// e = exact text from cell
// n = normalized value returned by the column parser
// f = search filter input value
// i = column index
也许这是完全错误的地方?
如何实现?
您可以使用 filter_selectSource
option to target that column (demo)
filter_selectSource: {
5: function(table, column, onlyAvail) {
// get an array of all table cell contents for a table column
var array = $.tablesorter.filter.getOptions(table, column, onlyAvail);
return array.sort(function(a, b) {
return a === b ? 0 : parseFloat(b) > parseFloat(a) ? 1 : -1
});
}
}
您还需要在 header 中添加 "filter-select-nosort"
class 以防止数据内部排序。
我想我会通过添加 "filter-select-desc-sort"
class 来更改排序来使这更容易。
我将 jquery tablesorter2 (https://mottie.github.io/tablesorter/docs/index.html) 与过滤器小部件一起使用。
现在我想将生成的下拉列表中值的排序顺序(不是 table-值)从 asc 更改为 desc。 我为此制作了一个 jsFiddle:
在这里您可以找到折扣栏。我想让它的值按降序排列,这样最大的折扣就出现在下拉列表的第一位。
有一些选项,但似乎没有合适的:
// each option has an associated function that returns a boolean
// function variables:
// e = exact text from cell
// n = normalized value returned by the column parser
// f = search filter input value
// i = column index
也许这是完全错误的地方?
如何实现?
您可以使用 filter_selectSource
option to target that column (demo)
filter_selectSource: {
5: function(table, column, onlyAvail) {
// get an array of all table cell contents for a table column
var array = $.tablesorter.filter.getOptions(table, column, onlyAvail);
return array.sort(function(a, b) {
return a === b ? 0 : parseFloat(b) > parseFloat(a) ? 1 : -1
});
}
}
您还需要在 header 中添加 "filter-select-nosort"
class 以防止数据内部排序。
我想我会通过添加 "filter-select-desc-sort"
class 来更改排序来使这更容易。