Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Grouping (multiple column grouping) - Fully Working #522

Closed
wants to merge 15 commits into from
Closed
Prev Previous commit
Next Next commit
Fully working Nested Grouping
fixind indentation problems
  • Loading branch information
ghiscoding committed Jan 24, 2013
commit fde4ff4938680df6b99833858c695071c44c2a9e
92 changes: 46 additions & 46 deletions examples/example-multigrouping.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,55 +205,55 @@ <h2>Demonstrates:</h2>
}

function groupByDurationPercentage() {
dataView.groupBy(
["duration", "percentComplete"],
[
(function (g) {
return "Duration: " + g.value + " <span style='color:green'>(" + g.count + " items)</span>";
}),
(function (g) {
return "Complete: " + g.value + " <span style='color:green'>(" + g.count + " items)</span>";
})
],
[
function (a, b) {
return a.value - b.value;
},
function (a, b) {
return a.value - b.value;
}
]
);
dataView.setAggregators([
new Slick.Data.Aggregators.Avg("percentComplete"),
new Slick.Data.Aggregators.Sum("cost")
dataView.groupBy(
["duration", "percentComplete"],
[
(function (g) {
return "Duration: " + g.value + " <span style='color:green'>(" + g.count + " items)</span>";
}),
(function (g) {
return "Complete: " + g.value + " <span style='color:green'>(" + g.count + " items)</span>";
})
],
[
function (a, b) {
return a.value - b.value;
},
function (a, b) {
return a.value - b.value;
}
]
);
dataView.setAggregators([
new Slick.Data.Aggregators.Avg("percentComplete"),
new Slick.Data.Aggregators.Sum("cost")
], true);
}

function groupByDurationEffortDriven() {
dataView.groupBy(
["duration", "effortDriven"],
[
(function (g) {
return "Duration: " + g.value + " <span style='color:green'>(" + g.count + " items)</span>";
}),
(function (g) {
var txtTrueFalse = (g.value === true) ? "True" : "False";
return "Effort-Driven: " + txtTrueFalse + " <span style='color:green'>(" + g.count + " items)</span>";
})
],
[
function (a, b) {
return a.value - b.value;
},
function (a, b) {
return a.value - b.value;
}
]
);
dataView.setAggregators([
dataView.groupBy(
["duration", "effortDriven"],
[
(function (g) {
return "Duration: " + g.value + " <span style='color:green'>(" + g.count + " items)</span>";
}),
(function (g) {
var txtTrueFalse = (g.value === true) ? "True" : "False";
return "Effort-Driven: " + txtTrueFalse + " <span style='color:green'>(" + g.count + " items)</span>";
})
],
[
function (a, b) {
return a.value - b.value;
},
function (a, b) {
return a.value - b.value;
}
]
);
dataView.setAggregators([
new Slick.Data.Aggregators.Avg("percentComplete"),
new Slick.Data.Aggregators.Sum("cost")
new Slick.Data.Aggregators.Sum("cost")
], true, true);
}

Expand All @@ -279,14 +279,14 @@ <h2>Demonstrates:</h2>
return a.value - b.value;
},
function (a, b) { // string sorting
var x = a.value, y = b.value;
var x = a.value, y = b.value;
return x == y ? 0 : (x > y ? 1 : -1);
}
]
);
dataView.setAggregators([
new Slick.Data.Aggregators.Avg("percentComplete"),
new Slick.Data.Aggregators.Sum("cost")
new Slick.Data.Aggregators.Sum("cost")
], true, false);
}

Expand Down
102 changes: 51 additions & 51 deletions slick.dataview-multigrouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@
options.groupItemMetadataProvider = new Slick.Data.GroupItemMetadataProvider();
}

// reset grouping variables
groupingGetter = [];
groupingGetterIsAFn = [];
groupingFormatter = [];
groupingComparer = [];
groups = [];
collapsedGroups = {};
// reset grouping variables
groupingGetter = [];
groupingGetterIsAFn = [];
groupingFormatter = [];
groupingComparer = [];
groups = [];
collapsedGroups = {};

if(valueGetter instanceof Array) {
for (var i = 0; i < valueGetter.length; i++) {
Expand All @@ -228,7 +228,7 @@
groupingFormatter[i] = valueFormatter[i];
groupingComparer[i] = sortComparer[i];
}
refresh();
refresh();
}else {
groupingGetterIsAFn[0] = typeof groupingGetter === "function";
groupingGetter[0] = valueGetter;
Expand Down Expand Up @@ -366,7 +366,7 @@
}

function collapseGroup(groupingValue) {
collapsedGroups[groupingValue] = true;
collapsedGroups[groupingValue] = true;
refresh();
}

Expand Down Expand Up @@ -396,22 +396,22 @@
group = new Slick.Group();
group.count = 0;
group.value = val;
group.groupby = dataset.__group ? dataset.groupby+"-->"+groupingColumn+":"+val : groupingColumn+":"+val;
group.level = groupLevel;
group.rows = [];
group.groupby = dataset.__group ? dataset.groupby+"-->"+groupingColumn+":"+val : groupingColumn+":"+val;
group.level = groupLevel;
group.rows = [];
groupsLcl[groupsLcl.length] = group;
groupsByVal[val] = group;
}

group.rows[group.count++] = r;
// do we have more level of grouping? if yes go deeper by recursion until we resurface back to parent level 0
if(groupLevel < groupingGetter.length-1) {
groupLevel++;
var grp = extractGroups(group, groupingGetter[groupLevel], groupLevel);
group.groups = grp;
groupLevel--;
}
// do we have more level of grouping? if yes go deeper by recursion until we resurface back to parent level 0
if(groupLevel < groupingGetter.length-1) {
groupLevel++;
var grp = extractGroups(group, groupingGetter[groupLevel], groupLevel);
group.groups = grp;
groupLevel--;
}
}

return groupsLcl;
Expand Down Expand Up @@ -439,13 +439,13 @@
function calculateTotals(groupsLcl) {
var idx = groupsLcl.length, g;
while (idx--) {
g = groupsLcl[idx];
g = groupsLcl[idx];
calculateGroupTotals(g);
// do we have more level of grouping? if yes go deeper by recursion until we resurface back to parent level 0
if(g.groups && aggregateAllLevels) {
calculateTotals(g.groups);
}
// do we have more level of grouping? if yes go deeper by recursion until we resurface back to parent level 0
if(g.groups && aggregateAllLevels) {
calculateTotals(g.groups);
}
}
}

Expand All @@ -472,13 +472,13 @@
g = groupsLcl[i];
groupedRows[gl++] = g;

// do we have more level of grouping? if yes go deeper by recursion until we resurface back to parent level 0
if(g.groups && !g.collapsed) {
var grpRows = flattenGroupedRows(g.groups);
for (var k = 0, kk = grpRows.length; k < kk; k++) {
groupedRows[gl++] = grpRows[k];
}
}
// do we have more level of grouping? if yes go deeper by recursion until we resurface back to parent level 0
if(g.groups && !g.collapsed) {
var grpRows = flattenGroupedRows(g.groups);
for (var k = 0, kk = grpRows.length; k < kk; k++) {
groupedRows[gl++] = grpRows[k];
}
}

if (!g.collapsed && !g.groups) {
for (var j = 0, jj = g.rows.length; j < jj; j++) {
Expand Down Expand Up @@ -684,19 +684,19 @@
return diff;
}

function multiSort(groupLcl, groupLevel) {
groupLcl.sort(groupingComparer[groupLevel]);
if (groupLevel < groupingComparer.length-1) {
groupLevel++;
for (var i = 0, l = groupLcl.length; i < l; i++) {
var grp = multiSort(groupLcl[i].groups, groupLevel);
groupLcl[i].groups = grp; // now sorted group
}
groupLevel--;
}
return groupLcl;
}
function multiSort(groupLcl, groupLevel) {
groupLcl.sort(groupingComparer[groupLevel]);
if (groupLevel < groupingComparer.length-1) {
groupLevel++;
for (var i = 0, l = groupLcl.length; i < l; i++) {
var grp = multiSort(groupLcl[i].groups, groupLevel);
groupLcl[i].groups = grp; // now sorted group
}
groupLevel--;
}

return groupLcl;
}

function recalc(_items, filter) {
rowsById = null;
Expand All @@ -719,11 +719,11 @@
calculateTotals(groups, 0);
}

if (groupingComparer.length > 1) {
multiSort(groups, 0);
}else {
groups.sort(groupingComparer[0]);
}
if (groupingComparer.length > 1) {
multiSort(groups, 0);
}else {
groups.sort(groupingComparer[0]);
}

newRows = flattenGroupedRows(groups);
}
Expand Down
3 changes: 1 addition & 2 deletions slick.groupitemmetadataprovider-multigrouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
function init(grid) {
_grid = grid;
_grid.onClick.subscribe(handleGridClick);
_grid.onKeyDown.subscribe(handleGridKeyDown);

_grid.onKeyDown.subscribe(handleGridKeyDown);
}

function destroy() {
Expand Down