使用jQuery表格排序器对表列进行排序
我想知道是否有办法使用表格分类器对列进行排序
因此我可以根据某些ID或任何内容自行排列列。
所以这里举例来说,如果我想对表进行排序以便Apple列
首先,我该怎么做?
演示: http : //jsfiddle.net/fKMqD/
码:
var rows = $('tr'); rows.eq(0).find('td').sort(function(a, b){ return $.text([a]) > $.text([b]) ? 1: -1; }).each(function(newIndex){ var originalIndex = $(this).index(); rows.each(function(){ var td = $(this).find('td'); if (originalIndex !== newIndex) td.eq(originalIndex).insertAfter(td.eq(newIndex)); }); });
无需插件。
我得到了它的工作
Potato Tomato Apple 20g 10gr 40gr