server_status_sorter.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // TODO: tablesorter shouldn't sort already sorted columns
  2. function initTableSorter (tabid) {
  3. var $table;
  4. var opts;
  5. switch (tabid) {
  6. case 'statustabs_queries':
  7. $table = $('#serverstatusqueriesdetails');
  8. opts = {
  9. sortList: [[3, 1]],
  10. headers: {
  11. 1: { sorter: 'fancyNumber' },
  12. 2: { sorter: 'fancyNumber' }
  13. }
  14. };
  15. break;
  16. }
  17. $table.tablesorter(opts);
  18. $table.find('tr:first th')
  19. .append('<div class="sorticon"></div>');
  20. }
  21. $(function () {
  22. $.tablesorter.addParser({
  23. id: 'fancyNumber',
  24. is: function (s) {
  25. return (/^[0-9]?[0-9,\.]*\s?(k|M|G|T|%)?$/).test(s);
  26. },
  27. format: function (s) {
  28. var num = jQuery.tablesorter.formatFloat(
  29. s.replace(PMA_messages.strThousandsSeparator, '')
  30. .replace(PMA_messages.strDecimalSeparator, '.')
  31. );
  32. var factor = 1;
  33. switch (s.charAt(s.length - 1)) {
  34. case '%':
  35. factor = -2;
  36. break;
  37. // Todo: Complete this list (as well as in the regexp a few lines up)
  38. case 'k':
  39. factor = 3;
  40. break;
  41. case 'M':
  42. factor = 6;
  43. break;
  44. case 'G':
  45. factor = 9;
  46. break;
  47. case 'T':
  48. factor = 12;
  49. break;
  50. }
  51. return num * Math.pow(10, factor);
  52. },
  53. type: 'numeric'
  54. });
  55. $.tablesorter.addParser({
  56. id: 'withinSpanNumber',
  57. is: function (s) {
  58. return (/<span class="original"/).test(s);
  59. },
  60. format: function (s, table, html) {
  61. var res = html.innerHTML.match(/<span(\s*style="display:none;"\s*)?\s*class="original">(.*)?<\/span>/);
  62. return (res && res.length >= 3) ? res[2] : 0;
  63. },
  64. type: 'numeric'
  65. });
  66. });