v7.3.0

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.

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

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

No results

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.

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

    Has a corresponding runtime showCount property.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isGroup : Booleantrue
    READONLY
    static
    ADVANCED
    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 true to 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.

  • isGroup : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of Group class, or subclass thereof.

Functions

Functions are methods available for calling on the class
    • Supply items to ColumnDragToolbar

    • onBeforeRenderRow( )
      private

      Called before rendering row contents, used to reset rows no longer used as group rows

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

    • toggleGroup( )
      private
      ASYNC

      Toggle groups with Space.

    • collapseAll( )
      ON-OWNER
      NON-LAZY-LOAD

      Collapse all groups. This function is exposed on Grid and can thus be called as grid.collapseAll()

    • expandAll( )
      ON-OWNER
      NON-LAZY-LOAD

      Expand all groups. This function is exposed on Grid and can thus be called as grid.expandAll()

    Events

    Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

    Event handlers

    Event handlers are callbacks called as a result of certain actions in this class

    Type 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
    id: group

    Source path

    Grid/feature/Group.js

    Demo

    examples/grouping

    Contents