Skip to content

Instantly share code, notes, and snippets.

@grifo
grifo / jquery.sort.js
Created February 1, 2012 21:30 — forked from ricardobeat/jquery.sort.coffee
Table sorter
$.fn.tableSort = function (col, order){
function toNumber(number) {
return parseFloat(number.replace(/\./g,"").replace(/,/g,"."))
}
return this.each(function(){
var rows = [].slice.call(this.rows, 0).sort(function(a,b){
if (order === 'desc') b = [a,a=b][0]; // troca-troca
var textA = $(a.cells[col]).text()
, textB = $(b.cells[col]).text()