Advertisement
Guest User

Untitled

a guest
Jul 13th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. headers: { 0: {sorter: false}, 1: {sorter: false} }
  2.  
  3. $("#nameCol").click(function() {
  4. var sorting = [[2, 0]]; /* sort 3rd col (Category) descending */
  5. $("#SearchResults").trigger("sorton", [sorting] ); /* SearchResults is the ID of the sortable table */
  6. return false; /* cancel default link action on a#nameCol */
  7. });
  8.  
  9. $('th').click(function() {
  10. handleHeaderClick(this);
  11. });
  12.  
  13. function handleHeaderClick(hdr) {
  14. if ($(hdr).hasClass('headerSortDown') == true) {
  15. $(hdr).removeClass('headerSortDown');
  16. $(hdr).addClass('headerSortUp');
  17. } else if ($(hdr).hasClass('headerSortUp') == true) {
  18. $(hdr).removeClass('headerSortUp');
  19. $(hdr).addClass('headerSortDown');
  20. } else {
  21. $('th', myTable).removeClass('headerSortUp headerSortDown');
  22. $(hdr).addClass('headerSortDown');
  23. }
  24. doSomething();
  25. };
  26.  
  27. function SaveSortOrder(tablename) {
  28. //returns an array of a tablesorter sort order
  29. var hdrorder = new Array();
  30. var hdrs = $("#" + tablename + " th");
  31. var arrayindex = 0;
  32. hdrs.each(function (index) {
  33. if ($(this).hasClass('headerSortDown')) {
  34. hdrorder[arrayindex] = [index, 0];
  35. arrayindex++;
  36. }
  37. else if ($(this).hasClass('headerSortUp')) {
  38. hdrorder[arrayindex] = [index, 1];
  39. arrayindex++;
  40. }
  41. });
  42.  
  43. return hdrorder;
  44. }
  45.  
  46. $("#yourtableId").on("sortEnd", function(event) {
  47. // prints the current sort order to the console
  48. console.log(event.target.config.sortList);
  49. });
  50.  
  51. lastSortList=$("#mytable")[0].config.sortList;
  52.  
  53. $("#mytable").trigger("sorton", [lastSortList]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement