I have a table with rows similar to the following. These rows get updated from time to time via jquery calls. Using jquery, how would I construct a function that reorders th
Thanks, Kai. I have distilled the code a little while preserving clarity. Generally, you don't want to sort the To sort in descending order, just reverse the return line as follows:thead or tfooter parts. So, it may be handy to just target only the elements in the tbody (although this was not in Chris' original question):
var tb = $('tbody');
var rows = tb.find('tr');
rows.sort(function(a, b) {
var keyA = $(a).attr('myAttribute');
var keyB = $(b).attr('myAttribute');
return keyA - keyB;
});
$.each(rows, function(index, row) {
tb.append(row);
});
return keyB - keyA;