Skip to content

Instantly share code, notes, and snippets.

@BenMQ
Created December 10, 2012 11:04
Show Gist options
  • Save BenMQ/4249996 to your computer and use it in GitHub Desktop.
Save BenMQ/4249996 to your computer and use it in GitHub Desktop.
table sorter.js
$(document).ready(function(){
$('#sort_connection').click(isort);
});
function isort(e) {
console.log('sorted');
var $table = $('#connection_data'); // $table = $('table')
var $rows = $('tr', $table).not(':eq(0)');
$rows = $rows.sort(isorter);
$table.append($rows);
}
function isorter(a, b) {
var liA = $('td:eq(7) > li', a);
var liB = $('td:eq(7) > li', b);
return (!liA.length && liB.length) ? 1 :((liA.length && !liB.length)? -1 : 0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment