Skip to content

Commit 8c840b2

Browse files
committed
Added support for predefined group values to DataView.
New grouping info properties: - predefinedValues - An array containing the grouping values for which groups should be included even if they are empty. - aggregateEmpty - Whether aggreggators should be run on empty groups.
1 parent 9f1c09b commit 8c840b2

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

slick.core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@
319319
* @property rows
320320
* @type {Array}
321321
*/
322-
this.rows = null;
322+
this.rows = [];
323323

324324
/**
325325
* Sub-groups that are part of the group.

slick.dataview.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
getter: null,
5555
formatter: null,
5656
comparer: function(a, b) { return a.value - b.value; },
57+
predefinedValues: [],
5758
aggregators: [],
59+
aggregateEmpty: false,
5860
aggregateCollapsed: false,
5961
aggregateChildGroups: false,
6062
collapsed: false
@@ -459,18 +461,28 @@
459461
var level = parentGroup ? parentGroup.level + 1 : 0;
460462
var gi = groupingInfos[level];
461463

464+
for (var i = 0, l = gi.predefinedValues.length; i < l; i++) {
465+
val = gi.predefinedValues[i];
466+
group = groupsByVal[val];
467+
if (!group) {
468+
group = new Slick.Group();
469+
group.value = val;
470+
group.level = level;
471+
group.groupingKey = (parentGroup ? parentGroup.groupingKey + groupingDelimiter : '') + val;
472+
groups[groups.length] = group;
473+
groupsByVal[val] = group;
474+
}
475+
}
476+
462477
for (var i = 0, l = rows.length; i < l; i++) {
463478
r = rows[i];
464479
val = gi.getterIsAFn ? gi.getter(r) : r[gi.getter];
465-
val = val || 0;
466480
group = groupsByVal[val];
467481
if (!group) {
468482
group = new Slick.Group();
469-
group.count = 0;
470483
group.value = val;
471484
group.level = level;
472485
group.groupingKey = (parentGroup ? parentGroup.groupingKey + groupingDelimiter : '') + val;
473-
group.rows = [];
474486
groups[groups.length] = group;
475487
groupsByVal[val] = group;
476488
}
@@ -524,7 +536,8 @@
524536
calculateTotals(g.groups, level + 1);
525537
}
526538

527-
if (gi.aggregators.length) {
539+
if (gi.aggregators.length && (
540+
gi.aggregateEmpty || g.rows.length || (g.groups && g.groups.length))) {
528541
calculateGroupTotals(g);
529542
}
530543
}
@@ -546,7 +559,7 @@
546559
// Let the non-leaf setGrouping rows get garbage-collected.
547560
// They may have been used by aggregates that go over all of the descendants,
548561
// but at this point they are no longer needed.
549-
g.rows = null;
562+
g.rows = [];
550563
}
551564
}
552565
}

0 commit comments

Comments
 (0)