如果您使用的是tablesorter gem,我相信你会用我的tablesorter叉。
我有this demo与解析器,使用复选框来更改行颜色。它还会使用复选框状态更新缓存,以便您可以对该列进行排序。
此解析器不能与原始版本的tablesorter一起使用。
// add parser through the tablesorter addParser method
$.tablesorter.addParser({
id: 'checkbox',
is: function(s) {
return false;
},
format: function(s, table, cell, cellIndex) {
var $t = $(table), $c = $(cell), c,
// resort the table after the checkbox status has changed
resort = false;
if (!$t.hasClass('hasCheckbox')) {
$t
.addClass('hasCheckbox')
// make checkbox in header set all others
.find('thead th:eq(' + cellIndex + ') input[type=checkbox]')
.bind('change', function(){
c = this.checked;
$t.find('tbody tr td:nth-child(' + (cellIndex + 1) + ') input').each(function(){
this.checked = c;
$(this).trigger('change');
});
})
.bind('mouseup', function(){
return false;
});
$t.find('tbody tr').each(function(){
$(this).find('td:eq(' + cellIndex + ')').find('input[type=checkbox]').bind('change', function(){
$t.trigger('updateCell', [$(this).closest('td')[0], resort]);
});
});
}
// return 1 for true, 2 for false, so true sorts before false
c = ($c.find('input[type=checkbox]')[0].checked) ? 1 : 2;
$c.closest('tr')[ c === 1 ? 'addClass' : 'removeClass' ]('checked');
return c;
},
type: 'numeric'
});
你不能只编辑tablesorter css文件吗? –
您可以调整您的CSS来将样式应用于排序表而不是修改JavaScript吗? – Greg
请张贴您的实际代码。你既没有在发布的代码片段中初始化'len'也没有使用'results'。 – Bergi