Add Grouping module
Add grouping module using grouping concepts from 2.x
Possibly include group tristate checkbox to aggregate template which selects/deselects all children (using intermediate state when some of the children are unselected).
Does this mean grouping is currently not supported in 3.0? I'm working to upgrade to fix a few issues I was having in v2 with getting the grid to load data when it was hidden during the initial load via ng-show.
Correct, grouping is currently not supported. But expandable rows is, which is very cool. :-)
is grouping going to be part of ui-grid, as i would like to upgrade from V2 but still need grouping
Yes, our intent is to have grouping added, hence this open item in the issue tracker. We've had a few people offer to assist in building it, but so far it hasn't turned into a pull request, and the core team are quite busy with the tasks they already have underway.
I'd say it will come, given the interest, but probably not in the next 1 month.
I'm thinking about trying to implement this. Having some trouble getting started. So far, I'm thinking about renderContainers, but really can't grok some of the concepts after sitting down with it for a few hours. If someone could throw some bones, that would be awesome.
EDIT: Seems that renderContainers are coupled (meant for) the pinning feature. Perhaps they, too, are just another rabbit hole.
EDIT: Perhaps, rowBuilder will do the trick.
I'd suggest having a chat on the gitter room - that's likely to get a good response. https://gitter.im/angular-ui/ng-grid
It's been a few months since there has been any chatter on this thread. How is this feature coming along? Really looking forward to using this grid in my project, so far it is amazing!
Here's some fairly awful, throw-away code that pulls it off :)
Keep in mind, this depends on underscore / lodash, and I don't know how well it plays with many other ui-grid features.
grouping.js
(function() {
'use strict';
var module = angular.module('ui.grid.grouping', ['ui.grid']);
module.constant('uiGridGroupingConstants', {
featureName: 'grouping'
});
module.service('uiGridGroupingService', ['$templateCache', 'uiGridGroupingConstants',
function($templateCache, uiGridGroupingConstants){
var service = {
initializeGrid: function (grid) {
//add feature namespace and any properties to grid for needed state
grid.grouping = {};
service.defaultGridOptions(grid.options);
},
defaultGridOptions: function(gridOptions) {
gridOptions.groupingRowHeight = gridOptions.groupingRowHeight || 30;
gridOptions.groupingRowHeaderWidth = gridOptions.groupingRowHeaderWidth || 40;
}
};
return service;
}]);
module.directive('uiGridGrouping', ['$timeout', 'uiGridGroupingConstants', 'uiGridGroupingService', 'gridUtil', 'GridRow', 'GridColumn', 'rowSorter',
function($timeout, uiGridGroupingConstants, uiGridGroupingService, gridUtil, GridRow, GridColumn, rowSorter) {
return {
replace: false,
priority: -1,
require: '^uiGrid',
scope: false,
compile: function() {
return {
pre: preLink,
post: postLink
};
}
};
function preLink($scope, $elm, $attrs, uiGridCtrl) {
var grid = uiGridCtrl.grid;
var columnDefs = grid.options.columnDefs;
var groupingColumns = _.filter(columnDefs, function(colDef) {
return colDef.grouping;
});
if (!groupingColumns.length) return;
grid.groupingColumns = groupingColumns;
uiGridGroupingService.initializeGrid(grid);
_.each(createGroupColDefs(), function(col, index) {
columnDefs.splice(0, 0, col);
});
function createGroupColDefs() {
var defs = [];
_.eachRight(groupingColumns, function(col, index) {
defs.push({
name: col.name + ' Group',
displayName: '',
enableSorting: false,
enableColumnResizing: false,
width: 40,
field: col.name + 'Group',
allowCellFocus: false
});
});
return defs;
}
}
function postLink($scope, $elm, $attrs, uiGridCtrl) {
var grid = uiGridCtrl.grid;
var columnDefs = grid.options.columnDefs;
var groupingColumns = grid.groupingColumns;
grid.registerRowsProcessor(rowsProcessor);
$timeout(function() {
uiGridCtrl.grid.handleWindowResize();
}, 0);
function rowsProcessor(rows, columns) {
_.each(groupingColumns, addSortPropertiesToColDef);
rowSorter.sort(grid, rows, columns);
_.each(groupingColumns, addGroupHeaderRows);
return rows;
function addGroupHeaderRows(groupCol, index) {
var lastVal = null;
for (var i = 0; i <= rows.length - 1; i++) {
var row = rows[i];
if (row.entity[groupCol.field] !== lastVal && row.entity[groupCol.field] !== undefined && !row.groupHeader) {
var currentRowCopy = angular.copy(row.entity);
var gridRow = new GridRow(currentRowCopy, i + 1, grid);
gridRow.entity[groupCol.name+'Group'] = row.entity[groupCol.field];
gridRow.groupHeader = true;
gridRow.groupLevel = index;
gridRow.allowCellFocus = false;
rows.splice(i, 0, gridRow);
i++;
lastVal = row.entity[groupCol.field];
}
}
}
function addSortPropertiesToColDef(col) {
var matchedCol = _.find(columns, function(mCol) {
return col.name === mCol.name;
});
_.assign(matchedCol.sort, {
direction: col.grouping.direction,
priority: col.grouping.priority
});
}
}
}
}]);
})();
Example Grid Options
var gridOptions = {
data: 'someData',
columnDefs: [
{ name: 'groupableYear', visible: false, grouping: { priority: -100, direction: 'desc' } },
{ name: 'groupableNumber', visible: false, grouping: { priority: -99, direction: 'desc' } },
{ name: 'name' },
{ name: 'date' }
]
};
The above example, gives you two levels of grouping. I really don't feel good about the code, but, this is what I've got. Hopefully, it will give someone some starting point for a rewrite.
I very quickly threw this response together. If you have issues, make a plunk, or something, and I'll see if I can help.
Dang... didn't expect that. I am not in a rush situation, will definitely try this code out if the feature doesn't get into the grid in the next month or so.
#2503 also offered an interesting solution to this, which was a different way to get to the outcome.
Ya detail grids are cool n all but they don't look as clean as the groups do.
I've pushed today, PR #2935. This is alpha only, so the API is be no means stable, refer the new tutorial for known limitations.
I'm closing this master issue for grouping, and we can raise new issues as new issue requests.