Group
Feature
Enables rendering and handling of row groups. The actual grouping is done in the store, but triggered by Shift + clicking headers, or by using the context menu, or by using two finger tap (one on header, one anywhere on grid). Use Shift + Alt + click, or the context menu, to remove a column grouper.
Groups can be expanded/collapsed by clicking on the group row or pressing Space when group row is selected. The actual grouping is done by the store, see group.
Grouping by a field performs sorting by the field automatically. It's not possible to prevent sorting. If you group, the records have to be sorted so that records in a group stick together. You can either control sorting direction, or provide a custom sorting function called groupSortFn to your feature config object.
For info on programmatically handling grouping, see StoreGroup.
Example snippets:
// grouping feature is enabled, no default value though
let grid = new Grid({
features : {
group : true
}
});
// use initial grouping
let grid = new Grid({
features : {
group : 'city'
}
});
// default grouper and custom renderer, which will be applied to each cell except the "group" cell
let grid = new Grid({
features : {
group : {
field : 'city',
ascending : false,
renderer : ({ isFirstColumn, count, groupRowFor, record }) => isFirstColumn ? `${groupRowFor} (${count})` : ''
}
}
});
// group using custom sort function
let grid = new Grid({
features : {
group : {
field : 'city',
groupSortFn : (a, b) => a.city.length < b.city.length ? -1 : 1
}
}
});
// can also be specified on the store
let grid = new Grid({
store : {
groupers : [
{ field : 'city', ascending : false }
]
}
});
// custom sorting function can also be specified on the store
let grid = new Grid({
store : {
groupers : [{
field : 'city',
fn : (recordA, recordB) => {
// apply custom logic, for example:
return recordA.city.length < recordB.city.length ? -1 : 1;
}
}]
}
});
Currently, grouping is not supported when using pagination, the underlying store cannot group data that is split into pages.
size param. See the renderer config for details.
Toggling a group collapsed state programmatically
You can easily toggle a group“s collapsed state, by passing a group member record like so:
// collapse the group for a certain record
grid.features.group.toggleCollapse(record, true);
Grouping by multi-value fields
The group field's value may be an array. This means that one record can be a member of more than one group. When this is the case, the second and subsequent generated groups contain a linked record which is a copy of the original record. Please note that some of the linked records fields are not shared, like id (which is always generated).
Keyboard shortcuts
This feature has the following default keyboard shortcuts:
| Keys | Action | Action description |
|---|---|---|
| Space | toggleGroup | When a group header is focused, this expands or collapses the grouped rows |
For more information on how to customize keyboard shortcuts, please see the Customizing keyboard shortcuts guide
This feature is enabled by default.
See also
- GroupSummary - Summary rows for groups
- Sort - Sorting feature
- group - Programmatic grouping
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
The sort direction of the groups.
Has a corresponding runtime ascending property.
-
The icon to use for the collapse icon in expanded state. Not applicable when using Scheduler in vertical mode.
-
The icon to use for the expand icon in collapsed state. Not applicable when using Scheduler in vertical mode.
-
The name of the record field to group by.
Has a corresponding runtime field property.
-
The height of group header rows. Can also be set on a per-group-header basis using the renderer. Not applicable when using Scheduler in vertical mode.
Has a corresponding runtime headerHeight property.
-
keyMap : Object<String, KeyMapConfig>
See Keyboard shortcuts for details. Not applicable when using Scheduler in vertical mode.
-
Set to
trueto show the number of members of each group in the group header. Not applicable when using Scheduler in vertical mode.Has a corresponding runtime showCount property.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Group class, or subclass thereof.
-
The sort direction of the groups.
Has a corresponding ascending config.
-
The name of the record field to group by.
Has a corresponding field config.
-
The height of group header rows. Can also be set on a per-group-header basis using the renderer. Not applicable when using Scheduler in vertical mode.
Has a corresponding headerHeight config.
-
Set to
trueto show the number of members of each group in the group header. Not applicable when using Scheduler in vertical mode.Has a corresponding showCount config.
-
Identifies an object as an instance of Group class, or subclass thereof.
Functions
Functions are methods available for calling on the class-
getColumnDragToolbarItems( )private
Supply items to ColumnDragToolbar
-
onBeforeRenderRow( )private
Called before rendering row contents, used to reset rows no longer used as group rows
-
onElementTouchStart( )private
Store touches when user touches header, used in onElementTouchEnd.
-
onStoreGroup( )private
Called when store grouping changes. Reflects on header and rerenders rows.
-
renderCell( )private
Called when a cell is rendered, styles the group rows first cell.
-
Toggle groups with Space.
-
Collapse all groups. This function is exposed on Grid and can thus be called as
grid.collapseAll() -
Expand all groups. This function is exposed on Grid and can thus be called as
grid.expandAll()