diff options
author | Michael Leibman <michael.leibman@gmail.com> | 2013-03-01 16:24:17 -0800 |
---|---|---|
committer | Michael Leibman <michael.leibman@gmail.com> | 2013-03-01 16:24:17 -0800 |
commit | 8c840b2e81e858f44b57f4bf351cfb0b5197af66 (patch) | |
tree | c3b14edc07384444f224455f8e0815276342a677 /slick.dataview.js | |
parent | 9f1c09b3296eaa762cc50aacac67f1be6242ab31 (diff) | |
download | SlickGrid-8c840b2e81e858f44b57f4bf351cfb0b5197af66.zip SlickGrid-8c840b2e81e858f44b57f4bf351cfb0b5197af66.tar.gz SlickGrid-8c840b2e81e858f44b57f4bf351cfb0b5197af66.tar.bz2 |
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.
Diffstat (limited to 'slick.dataview.js')
-rw-r--r-- | slick.dataview.js | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/slick.dataview.js b/slick.dataview.js index 85f2339..960ecee 100644 --- a/slick.dataview.js +++ b/slick.dataview.js @@ -54,7 +54,9 @@ getter: null, formatter: null, comparer: function(a, b) { return a.value - b.value; }, + predefinedValues: [], aggregators: [], + aggregateEmpty: false, aggregateCollapsed: false, aggregateChildGroups: false, collapsed: false @@ -459,18 +461,28 @@ var level = parentGroup ? parentGroup.level + 1 : 0; var gi = groupingInfos[level]; + for (var i = 0, l = gi.predefinedValues.length; i < l; i++) { + val = gi.predefinedValues[i]; + group = groupsByVal[val]; + if (!group) { + group = new Slick.Group(); + group.value = val; + group.level = level; + group.groupingKey = (parentGroup ? parentGroup.groupingKey + groupingDelimiter : '') + val; + groups[groups.length] = group; + groupsByVal[val] = group; + } + } + for (var i = 0, l = rows.length; i < l; i++) { r = rows[i]; val = gi.getterIsAFn ? gi.getter(r) : r[gi.getter]; - val = val || 0; group = groupsByVal[val]; if (!group) { group = new Slick.Group(); - group.count = 0; group.value = val; group.level = level; group.groupingKey = (parentGroup ? parentGroup.groupingKey + groupingDelimiter : '') + val; - group.rows = []; groups[groups.length] = group; groupsByVal[val] = group; } @@ -524,7 +536,8 @@ calculateTotals(g.groups, level + 1); } - if (gi.aggregators.length) { + if (gi.aggregators.length && ( + gi.aggregateEmpty || g.rows.length || (g.groups && g.groups.length))) { calculateGroupTotals(g); } } @@ -546,7 +559,7 @@ // Let the non-leaf setGrouping rows get garbage-collected. // They may have been used by aggregates that go over all of the descendants, // but at this point they are no longer needed. - g.rows = null; + g.rows = []; } } } |