From fd351f44831b5101a1a059d1806890935133ff56 Mon Sep 17 00:00:00 2001 From: Fotis Gimian Date: Sun, 10 May 2015 19:49:29 +1000 Subject: [PATCH] Repaired sorting of date columns --- puppetboard/static/coffeescript/tables.coffee | 35 ++++++++++++++----- puppetboard/static/js/tables.js | 20 +++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/puppetboard/static/coffeescript/tables.coffee b/puppetboard/static/coffeescript/tables.coffee index 1155182..65a3e81 100644 --- a/puppetboard/static/coffeescript/tables.coffee +++ b/puppetboard/static/coffeescript/tables.coffee @@ -1,21 +1,38 @@ $ = jQuery $ -> + +$.tablesorter.addParser( + id: 'timestamp' + + # Return false so this parser is not auto detected + is: (s) -> + false + + # Normalize the timestamp to epoch for sorting + format: (s) -> + moment.utc(s).unix() + + # The return value of our normalization function is an integer + type: 'numeric' +) + $('.nodes').tablesorter( - headers: - 4: - sorter: false - sortList: [[1,0]] + headers: + 2: sorter: 'timestamp' + 3: sorter: 'timestamp' + 4: sorter: false + sortList: [[1,0]] ) $('.facts').tablesorter( - sortList: [[0,0]] + sortList: [[0,0]] ) $('.dashboard').tablesorter( - headers: - 3: - sorter: false - sortList: [[0, 1]] + headers: + 2: sorter: 'timestamp' + 3: sorter: false + sortList: [[0, 1]] ) $('input.filter-table').parent('div').removeClass('hide') diff --git a/puppetboard/static/js/tables.js b/puppetboard/static/js/tables.js index df7673b..ac864dd 100644 --- a/puppetboard/static/js/tables.js +++ b/puppetboard/static/js/tables.js @@ -6,8 +6,25 @@ $(function() {}); + $.tablesorter.addParser({ + id: 'timestamp', + is: function(s) { + return false; + }, + format: function(s) { + return moment.utc(s).unix(); + }, + type: 'numeric' + }); + $('.nodes').tablesorter({ headers: { + 2: { + sorter: 'timestamp' + }, + 3: { + sorter: 'timestamp' + }, 4: { sorter: false } @@ -21,6 +38,9 @@ $('.dashboard').tablesorter({ headers: { + 2: { + sorter: 'timestamp' + }, 3: { sorter: false }