Created
April 11, 2011 23:04
-
-
Save bxt/914568 to your computer and use it in GitHub Desktop.
Sorting HTML-Tables (or anything) using jQuery and Javascript's native Array.prototype.sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tableRows=$("tr").detach(); | |
Array.prototype.sort.call(tableRows,function(a,b){ | |
// Compare two table rows by the numeric value of their first <td> | |
return a.firstChild.firstChild.nodeValue*1 < b.firstChild.firstChild.nodeValue*1 | |
}); | |
$("table").append(tableRows); | |
// Tested in Firefox 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment