Created
May 12, 2013 04:54
-
-
Save vishaltelangre/5562472 to your computer and use it in GitHub Desktop.
PROTIP: Sort things in both orders vice-versa (asc/desc) w/ jQuery.TinySort plugin.
This file contains hidden or 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
// custom function to sort by asc/desc | |
var sortOrders = {}; | |
function sortResultsUsing(pattern, key, callback) { | |
sortOrders[key] = (sortOrders[key] == "asc") ? "desc" : "asc"; | |
$('tbody.results>tr').tsort(pattern, { order: sortOrders[key] }); | |
callback(); | |
} | |
/* USAGE | |
--------- | |
$('.sortBy').on('click', function(e){ | |
e.preventDefault(); | |
patternToSortBy = $(this).data('sortTarget'); | |
sortResultsUsing(patternToSortBy, $(this).text(), function(){ | |
pagination.rebuild(); // already results were paginated, so updated pagination here | |
}); | |
// other logic... | |
}); | |
------ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment