TreeColumn

A column that displays a tree structure when using the Tree feature.

Default editor is a TextField.

TreeColumn provides configs to define icons for expanded / collapsed nodes, expanded folder / collapsed folder nodes and leaf nodes.

When the TreeColumn renders its cells, it will look for two special fields href and target. Specifying href will produce a link for the TreeNode, and target will have the same meaning as in an A tag:

{
   id        : 1,
   name      : 'Some external link'
   href      : '//www.website.com",
   target    : '_blank"
}

Snippet

new TreeGrid({
    appendTo : document.body,

    columns : [
         { type: 'tree', field: 'name' }
    ]
});

Tree column
//<code-header>
fiddle.title = 'Tree column';
//</code-header>
// grid with TreeColumn
const grid = new Grid({
    appendTo : targetElement,

    // makes grid as high as it needs to be to fit rows
    autoHeight : true,

    features : {
        tree : true
    },

    store : {
        tree : true,
        data : [
            {
                id       : 1,
                name     : 'ABBA',
                iconCls  : 'b-icon fa-users',
                expanded : true,
                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,
                expanded : true,
                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 }
    ]
});

Cell renderers

You can affect the contents and styling of cells in this column using a renderer function.

const grid = new Grid({
  columns : [{
      type       : 'tree',
      field      : 'name',
      text       : 'Name',
      renderer({ value, record }) {
        return `${value} (${record.childLevel})`
      }
    }]
});

Alternative: tree: true config

Instead of using type: 'tree', you can add tree rendering to any column type by configuring it with tree: true:

const grid = new TreeGrid({
    columns : [
        // These are equivalent:
        { type: 'tree', field: 'name' },
        { field: 'name', tree: true },

        // Any column type can be a tree column:
        { type: 'resourceInfo', tree: true, field: 'name' },
        { type: 'check', tree: true, field: 'done' }
    ]
});

Configs

86

Common

autoWidthColumn
fieldColumn
fitModeColumn
flexColumn
listenersEvents
maxWidthColumn
textColumn
widthColumn

Other

The icon to use for a parent node in collapsed state

The icon to use for the expand / collapse button in expanded state

The icon to use for a parent node in expanded state

The icon to use for the expand / collapse button icon in collapsed state

Size of the child indent in em. Resulting indent is indentSize multiplied by child level.

Sets the --b-tree-indent-size CSS variable. By default, the value of the variable set by the theme is used.

The icon to use for the leaf nodes in the tree

formulaColumn
pinnedColumn
readOnlyColumn

Rendering

Renderer function, used to format and style the content displayed in the cell. Return the cell text you want to display. Can also affect other aspects of the cell, such as styling.

As the TreeColumn adds its own cell content to the column, there is a limit to what is supported in the renderer function in comparison with an ordinary Column renderer. Most notably is that changing `cellElement` content can yield unexpected results as it will be updated later in the rendering process.

You can also return a DomConfig object describing the markup

new Grid({
    columns : [
        {
             type  : 'tree',
             field : 'name'
             text  : 'Name',
             renderer : ({ record }) => {
                 return {
                     class : 'myClass',
                     children : [
                         {
                             tag : 'i',
                             class : 'fa fa-pen'
                         },
                         {
                             tag : 'span',
                             text : record.name
                         }
                     ]
                 };
             }
        }
    ]
});

You can modify the row element too from inside a renderer to add custom CSS classes:

new Grid({
    columns : [
        {
            type     : 'tree',
            field    : 'name',
            text     : 'Name',
            renderer : ({ record, row }) => {
               // Add special CSS class to new rows that have not yet been saved
              row.cls.newRow = record.isPhantom;

              return record.name;
        }
    ]
});
You should never modify any records inside this method.
ParameterTypeDescription
renderDataObject

Object containing renderer parameters

renderData.cellElementHTMLElement

Cell element, for adding CSS classes, styling etc. Can be null in case of export

renderData.value*

Value to be displayed in the cell

renderData.recordModel

Record for the row

renderData.columnColumn

This column

renderData.gridGridBase

This grid

renderData.rowRow

Row object. Can be null in case of export. Use the row's API to manipulate CSS class names.

renderData.sizeObject

Set size.height to specify the desired row height for the current row. Largest specified height is used, falling back to configured rowHeight in case none is specified. Can be null in case of export

renderData.size.heightNumber

Set this to request a certain row height

renderData.size.configuredHeightNumber

Row height that will be used if none is requested

renderData.isExportBoolean

true if record is being exported to Excel/textual format to allow special handling during export.

renderData.isMeasuringBoolean

True if the column is being measured for a resizeToFitContent call. In which case an advanced renderer might need to take different actions.

Returns: String | DomConfig | null
cellClsColumn
clsColumn
iconColumn
tooltipColumn

Accessibility

ariaLabelColumn

Export

Integration

vueColumn

Interaction

collapsedColumn
draggableColumn
editorColumn
groupableColumn
hideableColumn
resizableColumn
sealedColumn
sortableColumn

Layout

alignColumn
hiddenColumn
lockedColumn
minWidthColumn
regionColumn

Menu

Merge cells

mergeableColumn

Misc

localeClassLocalizable
localizableLocalizable
tagsColumn
treeColumn

Summary

sumColumn
summariesColumn

Properties

158

Common

autoWidthColumn
fieldColumn
fitModeColumn
flexColumn
maxWidthColumn
textColumn
widthColumn

Class hierarchy

isTreeColumn: Boolean= truereadonly
Identifies an object as an instance of TreeColumn class, or subclass thereof.
isTreeColumn: Boolean= truereadonlystatic
Identifies an object as an instance of TreeColumn class, or subclass thereof.
isTreeColumnMixin: Boolean= truereadonlyTreeColumnMixin
Identifies an object as an instance of TreeColumnMixin class, or subclass thereof.
isTreeColumnMixin: Boolean= truereadonlystaticTreeColumnMixin
Identifies an object as an instance of TreeColumnMixin class, or subclass thereof.
isColumnColumn
isEventsEvents
isLocalizableLocalizable
isModelModel
isModelLinkModelLink
isModelStmModelStm
isTreeNodeTreeNode

Other

The icon to use for a parent node in collapsed state

The icon to use for the expand / collapse button in expanded state

The icon to use for a parent node in expanded state

The icon to use for the expand / collapse button icon in collapsed state

Size of the child indent in em. Resulting indent is indentSize multiplied by child level.

Sets the --b-tree-indent-size CSS variable. By default, the value of the variable set by the theme is used.

The icon to use for the leaf nodes in the tree

$namestaticModel
defaultsColumn
elementColumn
formulaColumn
gridColumn
pinnedColumn
readOnlyColumn
relationsstaticModel
subGridColumn
typestaticColumn
visibleColumn

Rendering

Renderer function, used to format and style the content displayed in the cell. Return the cell text you want to display. Can also affect other aspects of the cell, such as styling.

As the TreeColumn adds its own cell content to the column, there is a limit to what is supported in the renderer function in comparison with an ordinary Column renderer. Most notably is that changing `cellElement` content can yield unexpected results as it will be updated later in the rendering process.

You can also return a DomConfig object describing the markup

new Grid({
    columns : [
        {
             type  : 'tree',
             field : 'name'
             text  : 'Name',
             renderer : ({ record }) => {
                 return {
                     class : 'myClass',
                     children : [
                         {
                             tag : 'i',
                             class : 'fa fa-pen'
                         },
                         {
                             tag : 'span',
                             text : record.name
                         }
                     ]
                 };
             }
        }
    ]
});

You can modify the row element too from inside a renderer to add custom CSS classes:

new Grid({
    columns : [
        {
            type     : 'tree',
            field    : 'name',
            text     : 'Name',
            renderer : ({ record, row }) => {
               // Add special CSS class to new rows that have not yet been saved
              row.cls.newRow = record.isPhantom;

              return record.name;
        }
    ]
});
You should never modify any records inside this method.
ParameterTypeDescription
renderDataObject

Object containing renderer parameters

renderData.cellElementHTMLElement

Cell element, for adding CSS classes, styling etc. Can be null in case of export

renderData.value*

Value to be displayed in the cell

renderData.recordModel

Record for the row

renderData.columnColumn

This column

renderData.gridGridBase

This grid

renderData.rowRow

Row object. Can be null in case of export. Use the row's API to manipulate CSS class names.

renderData.sizeObject

Set size.height to specify the desired row height for the current row. Largest specified height is used, falling back to configured rowHeight in case none is specified. Can be null in case of export

renderData.size.heightNumber

Set this to request a certain row height

renderData.size.configuredHeightNumber

Row height that will be used if none is requested

renderData.isExportBoolean

true if record is being exported to Excel/textual format to allow special handling during export.

renderData.isMeasuringBoolean

True if the column is being measured for a resizeToFitContent call. In which case an advanced renderer might need to take different actions.

Returns: String | DomConfig | null
cellClsColumn
clsColumn
iconColumn
tooltipColumn

Accessibility

ariaLabelColumn

Editing

copyOfModel
isValidModel

Export

Fields

allFieldsstaticModel
autoExposeFieldsstaticModel
childrenFieldstaticModel
fieldMapstaticModel
fieldsstaticModel
idFieldstaticModel

Grouping

Identification

keyModel

Integration

vueColumn

Interaction

collapsedColumn
draggableColumn
editorColumn
groupableColumn
hideableColumn
resizableColumn
sealedColumn
sortableColumn

JSON

jsonModel

Layout

alignColumn
hiddenColumn
lockedColumn
minWidthColumn
regionColumn

Lifecycle

configBase

Linked records

hasLinksModelLink
isLinkedModelLink
recordLinksModelLink

Menu

Merge cells

mergeableColumn

Misc

localeHelperLocalizable
localeManagerLocalizable
stmModelStm
tagsColumn
treeColumn

Parent & children

allChildrenTreeNode
childLevelTreeNode
firstChildTreeNode
isLeafTreeNode
isLoadedTreeNode
isParentTreeNode
isRootTreeNode
lastChildTreeNode
nextSiblingTreeNode
parentTreeNode
parentIdTreeNode

Summary

sumColumn
summariesColumn

Functions

77

Configuration

applyDefaultsstaticBase

Editing

copyModel
getDataModel
removeModel
setModel

Events

Fields

addFieldstaticModel
getModel
processFieldstaticModel
removeFieldstaticModel

Identification

asIdstaticModel

JSON

toJSONModel

Lifecycle

destroystaticBase

Misc

equalsModel
initClassstaticBase
isOfTypeNamestaticBase
linkModelLink
mixinstaticBase
optionalLstaticLocalizable

Other

hideColumn
LstaticLocalizable
onEvents
relayAllEvents
showColumn
toggleColumn
triggerEvents
unEvents

Parent & children

appendChildTreeNode
bubbleTreeNode
bubbleWhileTreeNode
containsTreeNode
isExpandedTreeNode
removeChildTreeNode
traverseTreeNode

Events

5

Event handlers

5

Typedefs

2

CSS variables

13
NameDescription
--b-tree-loading-iconIcon to display when loading children (font icon)
--b-tree-icon-widthWidth of the tree icon
--b-tree-cell-gapGap between the internals of a tree cell
--b-tree-parent-font-weightParent row's font-weight
--b-tree-indent-sizeAmount to indent each level of the tree
--b-tree-leaf-icon-font-sizeSize of the leaf icon (font icon)
--b-tree-expander-icon-font-sizeSize of the expander icon (font icon)
--b-tree-expander-colorColor of the expander icon
--b-tree-parent-colorParent row's color
--b-tree-icon-colorColor of a tree icon
--b-tree-line-widthWidth of a tree line
--b-tree-line-colorColor of a tree line
--b-tree-line-offsetOffset of the tree line (adjust to align with the apps collapse/expand icon)