我找到了如何解决我的问题。我创建了一个过滤器,它返回一个最小值。因此,当我的排序为 asc 时,我的破折号保持在底部,而当我的排序为 desc 时,我的破折号保持在顶部。我认为当我的排序是 desc 时,破折号位于顶部更合乎逻辑,因为这就像我输入 0 ;)
所以这是我的过滤器:
$.tablesorter.addParser({
id: "dashSorter",
format: function(s) {
return ($.trim(s) === '-') ? Number.MIN_VALUE : $.tablesorter.formatFloat(s.replace(/[,:]/g, ""));
},
type: "numeric"
});
我把':'放在我的正则表达式中,因为我有时间以 HH:mm:ss 格式(你可以删除它)和我的脚本对我的表进行排序:
$("table[name=table_sorter]").tablesorter({
// initialize zebra striping and filter widgets
widgets : ['zebra', 'filter'],
headers : {
1 : {sorter:'dashSorter'},
2 : {sorter:'dashSorter'},
3 : {sorter:'dashSorter'}
},
widgetOptions : {
// css class applied to the table row containing the filters & the inputs within that row
filter_cssFilter : 'tablesorter-filter',
// If there are child rows in the table (rows with class name from "cssChildRow" option)
// and this option is true and a match is found anywhere in the child row, then it will make that row
// visible; default is false
filter_childRows : false,
// if true, filters are collapsed initially, but can be revealed by hovering over the grey bar immediately
// below the header row. Additionally, tabbing through the document will open the filter row when an input gets focus
filter_hideFilters : false,
// Set this option to false to make the searches case sensitive
filter_ignoreCase : true,
// jQuery selector string of an element used to reset the filters
filter_reset : '.reset',
// Delay in milliseconds before the filter widget starts searching; This option prevents searching for
// every character while typing and should make searching large tables faster.
filter_searchDelay : 300,
// Set this option to true to use the filter to find text from the start of the column
// So typing in "a" will find "albert" but not "frank", both have a's; default is false
filter_startsWith : false
}
});
我希望能帮助人们并很快见到你;)