0
這裏是jsFiddle。jquery sortElement:按表格數據的數值排序
正如您從小提琴中看到的那樣,total
列包含當前按文本排序的數字。
問:如何按數值對total
列進行排序?
var table = $('table');
$('#facility_header, #city_header, #total')
.wrapInner('<span title="sort this column"/>')
.each(function(){
var th = $(this),
thIndex = th.index(),
inverse = false;
th.click(function(){
table.find('td').filter(function(){
return $(this).index() === thIndex;
}).sortElements(function(a, b){
return $.text([a]) > $.text([b]) ?
inverse ? -1 : 1
: inverse ? 1 : -1;
}, function(){
// parentNode is the element we want to move
return this.parentNode;
});
inverse = !inverse;
});
});