Tree

Feature that makes the grid work more like a tree. Included by default in TreeGrid. Requires exactly one TreeColumn among grids columns. That column will have its renderer replaced with a tree renderer that adds padding and icon to give the appearance of a tree. The original renderer is preserved and also called.

Tree
//<code-header>
fiddle.title = 'Tree';
//</code-header>
targetElement.innerHTML = '<p>Tree feature requires a store with <code>{ tree: true }</code> and a TreeColumn among columns</p>';

const grid = new Grid({
    appendTo : targetElement,

    height : 500,

    features : {
        tree : true
    },

    store : {
        tree : true,
        data : [
            {
                id       : 1,
                name     : 'ABBA',
                iconCls  : 'b-icon fa-users',
                children : [
                    { id : 11, name : 'Anni-Frid', iconCls : 'b-icon fa-user' },
                    { id : 12, name : 'Bjorn', iconCls : 'b-icon fa-user' },
                    { id : 13, name : 'Benny', iconCls : 'b-icon fa-user' },
                    { id : 14, name : 'Agnetha', iconCls : 'b-icon fa-user' }
                ]
            },
            {
                id       : 2,
                name     : 'Roxette',
                iconCls  : 'b-icon fa-users',
                children : [
                    { id : 21, name : 'Per', iconCls : 'b-icon fa-user' },
                    { id : 22, name : 'Marie', iconCls : 'b-icon fa-user' }
                ]
            }
        ]
    },

    columns : [
        { type : 'tree', field : 'name', text : 'Name', flex : 1 }
    ]
});

This feature is disabled by default. When enabled, the feature cannot be disabled during runtime.

Keyboard shortcuts

This feature has the following default keyboard shortcuts:

Keys Action Action description
Space toggleCollapseByKey When focus on a parent node, this expands or collapses it's children
ArrowRight expandIfSingleColumn Expands a focused parent node if grid consist of one column only
Shift+ArrowRight expandByKey Expands a focused parent node
ArrowLeft collapseIfSingleColumn Collapses a focused parent node if grid consist of one column only
Shift+ArrowLeft collapseByKey Collapses a focused parent node
Please note that Ctrl is the equivalent to Command and Alt is the equivalent to Option for Mac users

For more information on how to customize keyboard shortcuts, please see our guide

Configs

12

Common

disabledInstancePlugin
listenersEvents

Other

Expand parent nodes when clicking on their cell

keyMap: Object<String, KeyMapConfig>

See Keyboard shortcuts for details

treeLines: Boolean= falseAlso a property

Show or hide tree lines

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

17

Common

disabledInstancePlugin

Class hierarchy

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

Other

Expand parent nodes when clicking on their cell

treeLines: Boolean= falseAlso a config

Show or hide tree lines

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Functions

36

Tree

Collapse a single node. This function is exposed on Grid and can thus be called as grid.collapse()

ParameterTypeDescription
idOrRecordString | Number | Model

Record (the node itself) or id of a node to collapse

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

Expand a single node. This function is exposed on Grid and can thus be called as grid.expand(idOrRecord)

ParameterTypeDescription
idOrRecordString | Number | Model

Record (the node itself) or id of a node to expand

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

Expand or collapse all nodes, as specified by param, starting at the passed node (which defaults to the root node)

ParameterTypeDescription
collapseBoolean

Set to true to collapse, false to expand (defaults to true)

topNodeModel

The topmost node from which to cascade a collapse. Defaults to the rootNode. Not included in the cascade if the root node is being used.

Expands parent nodes to make this node "visible". This function is exposed on Grid and can thus be called as grid.expandTo()

ParameterTypeDescription
idOrRecordString | Number | Model | String[] | Number[] | Model[]

Record (the node itself), or id of a node. Also accepts arrays of the same types.

scrollIntoViewBoolean

A flag letting you control whether to scroll the record into view

Expands the parent nodes in the tree to the provided depth.

ParameterTypeDescription
levelNumber

The depth to expand to. Passing level 0 means the top level root parents will be expanded.

collapseAllBoolean

Pass true to collapse all nodes before expanding

Collapse an expanded node or expand a collapsed. Optionally forcing a certain state. This function is exposed on Grid and can thus be called as grid.toggleCollapse()

ParameterTypeDescription
idOrRecordString | Number | Model

Record (the node itself) or id of a node to toggle

collapseBoolean

Force collapse (true) or expand (false)

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

LstaticLocalizable
onEvents
relayAllEvents
triggerEvents
unEvents

Events

9

Fired before a parent node record toggles its collapsed state.

// Adding a listener using the "on" method
tree.on('beforeToggleNode', ({ source, record, collapse }) => {

});
ParameterTypeDescription
sourceGrid

The firing Grid instance.

recordModel

The record being toggled.

collapseBoolean

true if the node is being collapsed.

Fired before a parent node record is collapsed.

// Adding a listener using the "on" method
tree.on('collapseNode', ({ source, record }) => {

});
ParameterTypeDescription
sourceGrid

The firing Grid instance.

recordModel

The record which has been collapsed.

Fired after a parent node record is expanded.

// Adding a listener using the "on" method
tree.on('expandNode', ({ source, record }) => {

});
ParameterTypeDescription
sourceGrid

The firing Grid instance.

recordModel

The record which has been expanded.

Fired after a parent node record toggles its collapsed state.

// Adding a listener using the "on" method
tree.on('toggleNode', ({ record, collapse }) => {

});
ParameterTypeDescription
recordModel

The record being toggled.

collapseBoolean

true if the node is being collapsed.

catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

9

Called before a parent node record toggles its collapsed state.

new Tree({
    onBeforeToggleNode({ source, record, collapse }) {

    }
});
ParameterTypeDescription
sourceGrid

The firing Grid instance.

recordModel

The record being toggled.

collapseBoolean

true if the node is being collapsed.

Called before a parent node record is collapsed.

new Tree({
    onCollapseNode({ source, record }) {

    }
});
ParameterTypeDescription
sourceGrid

The firing Grid instance.

recordModel

The record which has been collapsed.

Called after a parent node record is expanded.

new Tree({
    onExpandNode({ source, record }) {

    }
});
ParameterTypeDescription
sourceGrid

The firing Grid instance.

recordModel

The record which has been expanded.

Called after a parent node record toggles its collapsed state.

new Tree({
    onToggleNode({ record, collapse }) {

    }
});
ParameterTypeDescription
recordModel

The record being toggled.

collapseBoolean

true if the node is being collapsed.

onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

1