Skip to content

Instantly share code, notes, and snippets.

@jphase
Created February 27, 2014 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jphase/9261845 to your computer and use it in GitHub Desktop.
Save jphase/9261845 to your computer and use it in GitHub Desktop.
Add tablesorter parser to sort rows by column class (to easily sort by columns that have icons and such in them)
// Add custom tablesorter parser
$.tablesorter.addParser({
id: 'teams',
is: function(s) {
return false;
},
format: function(s, table, cell) {
return $(cell).attr('class') || s;
},
type: 'text'
});
// Add tablesorters to all tables
$('table').each(function(){
switch($(this).attr('id')) {
case 'teamlist':
// Sort teams tables
$(this).tablesorter({
headers: {
6: { sorter: 'teams' },
7: { sorter: 'teams' },
8: { sorter: 'teams' },
9: { sorter: 'teams' },
10: { sorter: 'teams' },
11: { sorter: 'teams' },
12: { sorter: 'teams' }
}
});
break;
default:
// Sort all other tables
$(this).tablesorter();
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment