Created
January 22, 2015 14:31
-
-
Save MartynJones87/3bbef5e6cbac047c4e5c to your computer and use it in GitHub Desktop.
Slick Grid Aggregate Sorting Snippet
This file contains 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
function groupByRegion() { | |
dataView.setGrouping([{ | |
getter: "DealerName", | |
formatter: function(g) { | |
return g.value + " <span style='color:green'>(" + g.count + " items) Projected Overspend: " + accounting.formatMoney(g.totals.sum.ProjOverspend) + "</span>"; | |
}, | |
aggregators: [ | |
new Slick.Data.Aggregators.Sum("ProjOverspend") | |
], | |
comparer: function(a, b) { | |
console.log('comparing'); | |
if(a['ProjOverspendTotal'] === undefined){ | |
console.log('a aggregation'); | |
a['ProjOverspendTotal'] = _.reduce(a.rows, function(memo, num){return memo + num['ProjOverspend'];}, 0); | |
} | |
if(b['ProjOverspendTotal'] === undefined){ | |
console.log('b aggregation'); | |
b['ProjOverspendTotal'] = _.reduce(b.rows, function(memo, num){return memo + num['ProjOverspend'];}, 0); | |
} | |
return b['ProjOverspendTotal'] - a['ProjOverspendTotal']; | |
}, | |
aggregateCollapsed: true, | |
collapsed: true, | |
lazyTotalsCalculation: false, | |
displayTotalsRow: false, | |
} | |
, { | |
getter: "Carline", | |
formatter: function(g) { | |
return g.value + " <span style='color:green'>(" + g.count + " items) Projected Overspend: " + accounting.formatMoney(g.totals.sum.ProjOverspend) + "</span>"; | |
}, | |
aggregators: [ | |
new Slick.Data.Aggregators.Sum("ProjOverspend") | |
], | |
aggregateCollapsed: true, | |
collapsed: true, | |
lazyTotalsCalculation: false, | |
displayTotalsRow: false, | |
}, { | |
getter: "LabourOperation", | |
formatter: function(g) { | |
return g.value + " <span>(" + g.count + " items) Projected Overspend: " + accounting.formatMoney(g.totals.sum.ProjOverspend) + "</span>"; | |
}, | |
aggregators: [ | |
new Slick.Data.Aggregators.Sum("ProjOverspend") | |
], | |
aggregateCollapsed: true, | |
collapsed: true, | |
lazyTotalsCalculation: false, | |
displayTotalsRow: false, | |
}, | |
]); | |
var i = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment