Group

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.

Group
//<code-header>
fiddle.title = 'Group';
//</code-header>
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.

You can control the group header heights using the headerHeight. Custom height for specific group header rows cannot be set with CSS, should instead be defined in a renderer function using the size param. See the renderer config for details.

This feature will not work properly when Store uses lazyLoad

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).

Multi group
//<code-header>
fiddle.title = 'Multi group';
//</code-header>
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.

Configs

19

Common

disabledInstancePlugin
listenersEvents

Other

The sort direction of the groups.

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.

groupSortFn: function

A function used to sort the groups. When grouping, the records have to be sorted so that records in a group stick together. Technically that means that records having the same field value should go next to each other. And this function (if provided) is responsible for applying such grouping order.

const grid = new Grid({
    features : {
        group : {
            // group by category
            field       : 'category',
            groupSortFn : (a, b) => {
                const
                    aCategory = a.category || '',
                    bCategory = b.category || '';

                // 1st sort by "calegory" field
                return aCategory > bCategory ? -1 :
                    aCategory < bCategory ? 1 :
                    // inside calegory groups we sort by "name" field
                    (a.name > b.name ? -1 : 1);
            }
        }
    }
});
ParameterTypeDescription
firstGroupRecord

The first group header record to compare

secondGroupRecord

The second group header record to compare

Returns: Number -

Returns 1 if first value is greater than second value, -1 if the opposite is true or 0 if they're equal

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.

keyMap: Object<String, KeyMapConfig>

See Keyboard shortcuts for details. Not applicable when using Scheduler in vertical mode.

Set to true to show the number of members of each group in the group header. Not applicable when using Scheduler in vertical mode.

By default, clicking anywhere in a group row toggles its expanded/collapsed state. Not applicable when using Scheduler in vertical mode.

Configure this as false to limit this to only toggling on click of the expanded/collapsed state icon.

Rendering

renderer: function

A function which produces the HTML for a group header. The function is called in the context of this Group feature object. Default group renderer displays the groupRowFor and count.

You should never modify any records inside this method.
ParameterTypeDescription
renderDataObject

Object containing renderer parameters

renderData.groupRowFor*

The value of the field for the group. Type depends on field used for grouping

renderData.recordModel

The group record representing the group

renderData.countNumber

Number of records in the group

renderData.columnColumn

The column the renderer runs for

renderData.isFirstColumnBoolean

True, if column is the first column. If RowNumberColumn is the real first column, it's not taken into account

renderData.groupColumnColumn

The column under which the field is shown

renderData.sizeObject

Sizing information for the group header row, only height is relevant

renderData.size.heightNumber

The height of the row, set this if you want a custom height for the group header row. That is UI part, so do not rely on its existence

renderData.gridGrid

The owning grid

renderData.rowElementHTMLElement

The owning row element

Returns: DomConfig | String | null

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

20

Common

disabledInstancePlugin

Class hierarchy

isGroup: Boolean= truereadonly
Identifies an object as an instance of Group class, or subclass thereof.
isGroup: Boolean= truereadonlystatic
Identifies an object as an instance of Group class, or subclass thereof.
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable

Other

ascending: Boolean= trueAlso a config

The sort direction of the groups.

The name of the record field to group by.

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.

Set to true to show the number of members of each group in the group header. Not applicable when using Scheduler in vertical mode.

By default, clicking anywhere in a group row toggles its expanded/collapsed state. Not applicable when using Scheduler in vertical mode.

Configure this as false to limit this to only toggling on click of the expanded/collapsed state icon.

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Functions

31

Grouping

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()

Other

Collapses or expands a group header record (you can also pass a record that is part of a group) depending on its current state.

ParameterTypeDescription
recordOrIdModel | String

Record or records id for a group row to collapse or expand

collapseBoolean

Force collapse (true) or expand (false)

LstaticLocalizable
onEvents
relayAllEvents
triggerEvents
unEvents

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Events

7

Fired when a group is going to be expanded or collapsed using the UI. Returning false from a listener prevents the operation

// Adding a listener using the "on" method
group.on('beforeToggleGroup', ({ groupRecord, groupRecords, collapse, domEvent }) => {

});
ParameterTypeDescription
groupRecordModel

[DEPRECATED] Use groupRecords param instead

groupRecordsModel[]

The group records being toggled

collapseBoolean

Collapsed (true) or expanded (false)

domEventEvent

The user interaction event (eg a click event) if the toggle request was instigated by user interaction.

Fired when one or more groups are expanded or collapsed

// Adding a listener using the "on" method
group.on('toggleGroup', ({ groupRecord, groupRecords, collapse, allRecords }) => {

});
ParameterTypeDescription
groupRecordModel

[DEPRECATED] Use groupRecords param instead

groupRecordsModel[]

The group records being toggled

collapseBoolean

Collapsed (true) or expanded (false)

allRecordsBoolean

True if this event is part of toggling all groups

catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

7

Called when a group is going to be expanded or collapsed using the UI. Returning false from a listener prevents the operation

new Group({
    onBeforeToggleGroup({ groupRecord, groupRecords, collapse, domEvent }) {

    }
});
ParameterTypeDescription
groupRecordModel

[DEPRECATED] Use groupRecords param instead

groupRecordsModel[]

The group records being toggled

collapseBoolean

Collapsed (true) or expanded (false)

domEventEvent

The user interaction event (eg a click event) if the toggle request was instigated by user interaction.

Called when one or more groups are expanded or collapsed

new Group({
    onToggleGroup({ groupRecord, groupRecords, collapse, allRecords }) {

    }
});
ParameterTypeDescription
groupRecordModel

[DEPRECATED] Use groupRecords param instead

groupRecordsModel[]

The group records being toggled

collapseBoolean

Collapsed (true) or expanded (false)

allRecordsBoolean

True if this event is part of toggling all groups

onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

2
GroupRecord: Object<String, *>

A record representing a group header.

In addition to the groupChildren property, there is only one field defined in this record. The name of the field is the same as the field used for grouping.

ParameterTypeDescription
groupChildrenModel[]

The records in the group

CSS variables

13
NameDescription
--b-group-header-font-weightGroup header font weight
--b-group-header-border-widthGroup header border width
--b-group-header-zindexGroup header z-index
--b-group-header-collapsing-zindexGroup header z-index during expand / collapse animation (to cover content moving underneath)
--b-group-collapse-iconGroup collapse / expand icon (font icon char)
--b-group-header-iconGrouping indicator shown in the column header (font icon char)
--b-group-header-backgroundGroup header background
--b-group-header-colorGroup header color
--b-group-header-icon-colorGroup header icon color
--b-group-header-border-colorGroup header border color
--b-group-header-stripe-backgroundGroup header background when striping rows
--b-group-count-badge-backgroundGroup count badge background
--b-group-count-badge-colorGroup count badge color