使用逗号分隔符的表排序不起作用
Tablesorting with comma seperator not working
我正在尝试使用 table 排序插件对 table 中的数据进行排序,但数据使用逗号 (,) 作为分隔符,因此排序不正确。我认为它正在将数字视为一个字符串。在 google 的帮助下,我找到了一些代码,但这些代码对我不起作用。这是我到目前为止尝试过的方法。
$(document).ready(function(){
jQuery.tablesorter.addParser({
id: "fancyNumber",
is: function(s) {
return /^[0-9]?[0-9,\.]*$/.test(s);
},
format: function(s) {
return jQuery.tablesorter.formatFloat( s.replace(/,/g,'') );
},
type: "numeric"
});
$("#myTable").tablesorter({
widgets : ['zebra']
});
});
请告诉我哪里做错了。
我也给了专栏 class <th width="62" class="{sorter: 'fancyNumber'}">column</th>
。
如果您在 class 名称中设置排序器,如下所示:
<th width="62" class="{sorter: 'fancyNumber'}">column</th>
确保您也在 metadata addon 中加载,因为处理该格式需要它。
或者,如果您不想使用该插件,您可以使用 headers
选项设置解析器:
$(function(){
$('table').tablesorter({
headers : {
0 : { sorter: 'fancyNumber' }
}
});
});
我正在尝试使用 table 排序插件对 table 中的数据进行排序,但数据使用逗号 (,) 作为分隔符,因此排序不正确。我认为它正在将数字视为一个字符串。在 google 的帮助下,我找到了一些代码,但这些代码对我不起作用。这是我到目前为止尝试过的方法。
$(document).ready(function(){
jQuery.tablesorter.addParser({
id: "fancyNumber",
is: function(s) {
return /^[0-9]?[0-9,\.]*$/.test(s);
},
format: function(s) {
return jQuery.tablesorter.formatFloat( s.replace(/,/g,'') );
},
type: "numeric"
});
$("#myTable").tablesorter({
widgets : ['zebra']
});
});
请告诉我哪里做错了。
我也给了专栏 class <th width="62" class="{sorter: 'fancyNumber'}">column</th>
。
如果您在 class 名称中设置排序器,如下所示:
<th width="62" class="{sorter: 'fancyNumber'}">column</th>
确保您也在 metadata addon 中加载,因为处理该格式需要它。
或者,如果您不想使用该插件,您可以使用 headers
选项设置解析器:
$(function(){
$('table').tablesorter({
headers : {
0 : { sorter: 'fancyNumber' }
}
});
});