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.
const grid = new Grid({ appendTo : targetElement, // makes grid as high as it needs to be to fit rows autoHeight : true, features : { // group by food group : 'food' }, data : DataGenerator.generateData(5), columns : [ { field : 'name', text : 'Name', flex : 1 }, { field : 'food', text : 'Favorite food', flex : 1 }, { field : 'city', text : 'City', flex : 1 } ] }); 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).
const grid = new Grid({ appendTo : targetElement, // makes grid as high as it needs to be to fit rows autoHeight : true, features : { // group by food group : 'foods' }, store : { fields : [ 'name', { name : 'foods', type : 'array' }, 'city' ] }, data : [ { id : 1, name : 'Bruce Wayne', foods : ['Pizza', 'Sushi', 'Burgers'], city : 'Gotham' }, { id : 2, name : 'Clark Kent', foods : ['Pizza', 'Burgers'], city : 'Metropolis' }, { id : 3, name : 'Barry Allen', foods : ['Pizza', 'Sushi'], city : 'Central City' }, { id : 4, name : 'Diana Prince', foods : ['Burgers', 'Sushi'], city : 'Themyscira' } ], columns : [ { field : 'name', text : 'Name', flex : 1 }, { field : 'foods', text : 'Favorite foods', flex : 1, renderer : ({ record, value }) => { if (record.isGroupHeader) { return value; } return value.join(', '); } }, { field : 'city', text : 'City', flex : 1 } ] }); 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.
-
Internal listeners, that cannot be removed by the user.
-
The widget which this plugin is to attach to.
Has a corresponding runtime client property.
-
Set to
falseto disable localization of this object.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Events class, or subclass thereof.
-
Identifies an object as an instance of Group class, or subclass thereof.
-
Identifies an object as an instance of Localizable class, or subclass thereof.
-
A class property getter for the default values of internal properties for this class.
-
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.
-
An empty array that can be used as a default value.
-
An empty object that can be used as a default value.
-
Identifies an object as an instance of Group class, or subclass thereof.
-
Identifies an object as an instance of InstancePlugin class, or subclass thereof.
-
Returns a copy of the full configuration which was used to configure this object.
-
This property is set to
truebefore theconstructorreturns. -
This property is set to
trueon entry to the destroy method. It remains on the objects after returning fromdestroy(). If isDestroyed istrue, this property will also betrue, so there is no need to test for both (for example,comp.isDestroying || comp.isDestroyed). -
The Widget which was passed into the constructor, which is the Widget we are providing extra services for.
Has a corresponding client config.
-
Get the global LocaleHelper
-
Get the global LocaleManager
Functions
Functions are methods available for calling on the class-
This optional class method is called when a class is mixed in using the mixin() method.
-
Registers this class type with its Factory
-
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.
-
Internal function used to hook destroy() calls when using thisObj
-
Internal function used restore hooked destroy() calls when using thisObj
-
Auto detaches listeners registered from start, if set as detachable
-
Internal function used to run a callback function after an event is triggered
-
Removes all listeners registered to this object by the application.
-
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() -
This will merge a feature's (subclass of InstancePlugin) keyMap with it's client's keyMap.
Events
Events are triggered for certain actions in this class and can be listened for to react to those actions in your codeEvent handlers
Event handlers are callbacks called as a result of certain actions in this classType definitions
CSS variables
CSS variables that can be set to adjust appearance| Name | Description |
|---|---|
| --b-group-collapse-icon | Group collapse / expand icon (font icon char) |
| --b-group-count-badge-background | Group count badge background |
| --b-group-count-badge-color | Group count badge color |
| --b-group-header-background | Group header background |
| --b-group-header-border-color | Group header border color |
| --b-group-header-border-width | Group header border width |
| --b-group-header-collapsing-zindex | Group header z-index during expand / collapse animation (to cover content moving underneath) |
| --b-group-header-color | Group header color |
| --b-group-header-font-weight | Group header font weight |
| --b-group-header-icon | Grouping indicator shown in the column header (font icon char) |
| --b-group-header-icon-color | Group header icon color |
| --b-group-header-stripe-background | Group header background when striping rows |
| --b-group-header-zindex | Group header z-index |