From 40c242c3f6e9de093f68ad3e1f8887ae49a28b84 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 17 Mar 2015 03:05:59 +0100 Subject: add table sort --- web/src/js/store/view.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'web/src/js/store') diff --git a/web/src/js/store/view.js b/web/src/js/store/view.js index 9bf31c52..204d22da 100644 --- a/web/src/js/store/view.js +++ b/web/src/js/store/view.js @@ -1,7 +1,6 @@ var EventEmitter = require('events').EventEmitter; var _ = require("lodash"); - var utils = require("../utils.js"); function SortByStoreOrder(elem) { @@ -40,17 +39,25 @@ _.extend(StoreView.prototype, EventEmitter.prototype, { this.store.removeListener("recalculate", this.recalculate); }, recalculate: function (filt, sortfun) { - if (filt) { - this.filt = filt.bind(this); - } - if (sortfun) { - this.sortfun = sortfun.bind(this); - } + filt = filt || default_filt; + sortfun = sortfun || default_sort; + filt = filt.bind(this); + sortfun = sortfun.bind(this) + this.filt = filt; + this.sortfun = sortfun; - this.list = this.store.list.filter(this.filt); + this.list = this.store.list.filter(filt); this.list.sort(function (a, b) { - return this.sortfun(a) - this.sortfun(b); - }.bind(this)); + var akey = sortfun(a); + var bkey = sortfun(b); + if(akey < bkey){ + return -1; + } else if(akey > bkey){ + return 1; + } else { + return 0; + } + }); this.emit("recalculate"); }, index: function (elem) { -- cgit v1.2.3