Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartynJones87/3bbef5e6cbac047c4e5c to your computer and use it in GitHub Desktop.
Save MartynJones87/3bbef5e6cbac047c4e5c to your computer and use it in GitHub Desktop.
Slick Grid Aggregate Sorting Snippet
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