Sorting an HTML table using JQuery

function sortTable(table, order, nr) { var asc = order === 'asc', tbody = table.find('tbody'); tbody.find('tr').sort(function(a, b) { if (asc) { return $('td:nth-child('+ nr +')', a).text().localeCompare($('td:nth-child('+ nr +')', b).text()); } else { return $('td:nth-child('+ nr +')', b).text().localeCompare($('td:nth-child('+ nr +')', a).text()); } }).appendTo(tbody); } sortTable($('#mytable'),'asc', 1); References: Native Javascript solutions: https://stackoverflow.com/questions/22906760/jquery-sort-table-data JQuery solutions: Echoed from: https://blog.niklasottosson.com/javascript/jquery-sort-table-rows-on-column-value/ http://jsfiddle.net/6sskjbod/1682/

Good Javascript Resources

http://www.hunlock.com/blogs/Essential_Javascript_–_A_Javascript_Tutorial — A well-written javascript reference series authored by Patrick Hunlock; has discussions on best practices, pros and cons; Has useful sample prototypes for method extensions; has downloadable PDF versions for some of the topics http://www.devshed.com/c/a/JavaScript/JavaScript-Exception-Handling/ — A short but concise article on Javascript exception handling