Table Sorting With Jquery
How to implement table Sorting According to it's any column by Jquery. I don't want any plugin. Just by pure jquery.
Solution 1:
We can use jquery.
var $tbody = $('table tbody');
$tbody.find('tr').sort(function (a, b) {
var tda = $(a).find('td:eq(' + ColumnIndex + ')').text(); // Use your wished column indexvar tdb = $(b).find('td:eq(' + ColumnIndex + ')').text(); // Use your wished column index// if a < b return 1return tda > tdb ? 1// else if a > b return -1
: tda < tdb ? -1// else they are equal - return 0
: 0;
}).appendTo($tbody);
Use < instead of >for descending.
Post a Comment for "Table Sorting With Jquery"