function OrderBy(a,b) {
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
SortBy = function($th) {
var $tbody = $th.closest('tbody');
var $table = $tbody.parent();
$tbody.detach();
$('#Processing').show('fast',function () {
var column = $th.index();
var rows = $tbody.find('tr').get();
rows.sort(function(rowA,rowB) {
var keyA = $(rowA).children('td').eq(column).text();
var keyB = $(rowB).children('td').eq(column).text();
return OrderBy(keyA,keyB);
});
$.each(rows, function(index,row) {
$tbody.append(row);
});
$table.append($tbody);
});
};
Tell me more
×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.
|
|||||
|
You could read the cell texts before sorting, so that it doesn't have to happen repeatedly in the order function:
|
||||
|