v7.3.0

TreeGroup
Feature

A feature that allows transforming a flat dataset (or the leaves of a hierarchical) into a tree by specifying a record field per parent level. Parents are generated based on each leaf's value for those fields.

This feature can be used to mimic multi grouping or to generate another view for hierarchical data. The actual transformation happens in a new store, that contains links to the original records. The original store's structure is kept intact and will be plugged back in when calling clearGroups. When grouping on a column field, the column“s format method will be used to format the value to group by (relevant for NumberColumn, DateColumn etc.)

Any modification of the links is relayed to the original store. So cell editing and other features will work as expected and the original data will be updated.

Combine this feature with GroupBar to allow users to drag-drop column headers to group the tree store.
Please note that this feature requires using a TreeGrid or having the Tree feature enabled.

This snippet shows how the sample dataset used in the demo above is transformed:

const grid = new TreeGrid({
    // Original data
    data : [
        { id : 1, name : 'Project 1', children : [
            { id : 11, name : 'Task 11', status : 'wip', prio : 'high' },
            { id : 12, name : 'Task 12', status : 'done', prio : 'low' },
            { id : 13, name : 'Task 13', status : 'done', prio : 'high' }
        ]},
        { id : 2, name : 'Project 2', children : [
            { id : 21, name : 'Task 21', status : 'wip', prio : 'high' },
        ]}
    ],

features : { treeGroup : { // Fields to build a new tree from levels : [ 'prio', 'status' ] } } });

// Resulting data [ { name : 'low', children : [ { name : 'done', children : [ { id : 12, name : 'Task 12', status : 'done', prio : 'low' } ]} ]}, { name : 'high', children : [ { name : 'done', children : [ { id : 13, name : 'Task 13', status : 'done', prio : 'high' } ]}, { name : 'wip', children : [ { id : 11, name : 'Task 11', status : 'wip', prio : 'high' }, { id : 21, name : 'Task 21', status : 'wip', prio : 'low' } ]} ]} ]

Generated parent records are indicated with generatedParent and key properties. The first one is set to true and the latter one has a value for the group the parent represents.

This feature does not work when the store is configured with lazyLoad.

Summaries

You can also show summaries in each group row, by configuring columns with sum.

new Grid({
    features : { treeGroup : true },
    columns : [
        {
            text  : 'Name',
            field : 'name',
            flex  : 3,
            type  : 'tree'
        },
        {
            type  : 'number',
            text  : 'Capacity',
            field : 'capacity',
            flex  : 1,
            sum   : 'add'
        },
        {
            type  : 'number',
            text  : 'Crew',
            field : 'crew',
            flex  : 1,
            sum   : 'add'
        }
    ]
});

Important information

Using the TreeGroup feature comes with some caveats:

  • Generated parents are read-only, they cannot be edited using the default UI.
  • Moving nodes manually in the tree is not supported while it is grouped. The linked records have their own parentId fields, not linked to the original records value.
  • The generated structure is not meant to be persisted.
Please note that this feature is not supported in vertical mode in Scheduler. If the Grid is stateful, the group configuration will be stored, but only string based group levels (e.g. ['city']).

This feature is disabled by default.

See also

  • Tree - Tree feature for hierarchical data
  • Group - Grouping feature for flat data
No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • Specify as true to make generated parents start expanded.

  • True to hide grouped columns. Only supported when using String to define levels.

  • parentCls : Stringb-generated-parent

    CSS class to apply to the generated parents.

  • The number of milliseconds to wait after scheduleRefreshGroups call before actually refreshing groups. Each further scheduleRefreshGroups call during that timeout will restart the timer.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isGrouped : Boolean
    READONLY

    Indicates if the feature has applied grouping and the component uses a transformed version of the store.

  • originalStore : Store
    READONLY

    The original store used by the component before applying grouping. Use this to modify / load data while tree grouping is active.

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

Functions

Functions are methods available for calling on the class
    • refreshGroups( )
      private
      ON-OWNER
      NON-LAZY-LOAD

      Refreshes the store tree grouping by re-applying the current transformation.

      // Refresh groups
      grid.refreshGroups();
      

    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

    id: treeGroup

    Source path

    Grid/feature/TreeGroup.js

    Demo

    examples/tree-grouping

    Contents