-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[FEAT] Multiple grouped columns #127
Comments
Hi, so you want two columns to have expand and collapse feature?? This is instead of having one column with all group nodes?? So in your example, region in first col, area in second col, and city
|
Thanks for extremely prompt reply! Exactly that. Col 1 has groupKeys of Continent, Country, City Yes possibly a third too. |
ok i've checked something into the branch 'selection' if you want to grab that branch (won't be merging for a few days, but it's stable, so you can grab the branch). new option: groupSuppressGroupColumn when set to true, there is no grouping column. so if you just set it to true, and do nothing else, then your grid will be a bit useless, as there will be no way to expand the groups. however that's where you come in - you can provided your own cell renderers. i'd suggest you create a cell renderer that takes the level of grouping to show (eg 1, 2, 3 etc) and then provides whatever GUI you want to show to expand / contract that group. to expand a group, just set the expanded=true on the node, and call the api function groupExpandedOrCollapsed. that's how i would intend you to do it. grid provides a quick 'default' grouping feature (which you can now turn off). if you want to customise, then do that with cell renderers. ok - don't see any more grid changes, so closing this issue! |
fantastic! thanks so much |
For others wanting to do this here is a code snippet that might help you var groupKeys = ['Region', 'Country', 'City', 'Area'];
var columns = [
{
field: "Region",
cellRenderer: regionRenderer,
},
{
field: "Area",
cellRenderer: areaRenderer,
},
{
field: "Population",
}];
/**
* render column 1 with expand collapse
*/
function regionRenderer(params) {
if (params.node.level >= groupKeys.length - 1) {
//dont render leaves in col 1 (ie area/constituency)
return "";
}
return groupCellRenderer(params);
}
/**
* render area with expand collapse for consituency
*/
function areaRenderer(params) {
if (params.node.level < groupKeys.length - 1) {
//dont render parents (ie region, country etc)
return "";
}
return groupCellRenderer(params);
}
/**
* generic expand/collapse cell renderer
* dont use angular to keep it speedy
*/
function groupCellRenderer(params) {
var cellEl = document.createElement('span');
cellEl.onclick = function () {
params.node.expanded = !params.node.expanded;
params.api.onGroupExpandedOrCollapsed();
};
var isGroupNode = !!params.node.key; //group node if group key not empty;
if (isGroupNode) {
//expand icon
var iconClass = params.node.expanded ? "fa-minus-square-o" : "fa-plus-square-o"; //font awesome icon classes
var iconEl = document.createElement('i');
iconEl.className = "fa " + iconClass;
cellEl.appendChild(iconEl);
}
//text
var textEl = document.createElement('span');
var text = isGroupNode ? params.node.key : params.value;
textEl.innerHTML = " " + text;
cellEl.appendChild(textEl);
return cellEl;
}
//return field totals
function groupAggFn(nodes) {
var agg = {
Population: 0,
};
nodes.forEach(function (node) {
agg.Population += node.data.Population;
});
return agg;
}
////////// in link function //////
$scope.gridOptions = {
columnDefs: columns,
rowData: someData,
rowSelection: "single",
enableColResize: true,
enableSorting: true,
enableFilter: true,
groupKeys: groupKeys,
groupAggFunction: groupAggFn,
groupSuppressGroupColumn: true, //handle our own group rendering of expand/collapse
}; |
thanks @axelnormand :) |
hi axelnormand , Can you provide the your example with js field which may help us |
I found out that using floating row at bottom. |
Hi, this doesn't look like it ever made it into the production release? This would be useful for us as well but |
Hello
I'm looking to enhance angular grid to allow to allow you to specify multiple sets of grouped columns
Plus modify the look and feel so set of grouped column only renders in one column in the table rather than spread out horizontally across the grouped rows
Hopefully this attempt at an ASCII diagram explains it better:
Notice also how "North" is one row below "London" too
How would one suggest going about this change?
I can either create a custom group cell renderer for that second grouping in Area using groupInnerCellRenderer
Or is it easier to fork angular grid and add new option to specify multi levels of groupKeys?
Any suggestions appreciated.
Thank you
The text was updated successfully, but these errors were encountered: