1,汉字排序
$(function(){
$("table").tablesorter({
//配置为localeCompare比较方式
textSorter: function(a, b, direction, columnIndex, table){
return a.localeCompare(b);
}
});
});
2,固定序号
$.tablesorter.addWidget({
id: 'fixFirstNumber',
format: function(table, config, widgetOptions, initFlag) {
for(var i=1;i<table.rows.length;i++){
//console.log(table.rows[i].cells[0].innerHTML);
table.rows[i].cells[0].innerHTML = i;
}
}
});
$("table").tablesorter({
widgets: ['fixFirstNumber'],
})
本文介绍了一种使用JavaScript实现的表格数据排序方法,并通过localeCompare函数实现了汉字排序。此外,还提供了一个固定序号的解决方案,确保了表格中序号的一致性和正确性。

被折叠的 条评论
为什么被折叠?



