我不确定你是否想在两者之间添加一个空行或者只是增加行高,所以我选择了后者。这是我做的小部件和demo:
$.tablesorter.addWidget({
id: 'spacer',
format: function(table) {
var c = table.config,
$t = $(table),
$r = $t.find('tbody').find('tr'),
i, l, last, col, rows, spacers = [];
if (c.sortList && c.sortList[0]) {
$t.find('tr.spacer').removeClass('spacer');
col = c.sortList[0][0]; // first sorted column
rows = table.config.cache.normalized;
last = rows[0][col]; // text from first row
l = rows.length;
for (i=0; i < l; i++) {
// if text from row doesn't match last row,
// save it to add a spacer
if (rows[i][col] !== last) {
spacers.push(i-1);
last = rows[i][col];
}
}
// add spacer class to the appropriate rows
for (i=0; i<spacers.length; i++){
$r.eq(spacers[i]).addClass('spacer');
}
}
}
});
$('table').tablesorter({
widgets : ['spacer']
});
更新:我的tablesorter的叉可以跨多个tbodies排序,所以上面的脚本不无稍作修改rows = table.config.cache[0].normalized;
工作 - 在这里是一个updated demo是与我的叉子一起工作。上面的代码将与原始的tablesorter插件一起工作。
你可以发布html和jsfiddle吗? – elclanrs 2012-02-12 18:16:19
@elclanrs嗨 - jsbin好吗?我也认为这个小部件代码绝对是正确的路径,但我没有搞清楚 - http://tablesorter.com/docs/example-widgets.html – waffl 2012-02-12 18:20:18