TreeGrid
A TreeGrid combines hierarchical tree data with a full-featured grid. It must be configured with exactly one TreeColumn (type: tree), but can also have an arbitrary number of other columns. Most features that can be used with Grid also work with TreeGrid, except the Group feature.
const treeGrid = new TreeGrid({
appendTo : document.body,
columns : [
{ type : 'tree', field : 'name', text : 'Name', flex : 1 },
{ field : 'size', text : 'Size', width : 100 }
],
data : [
{
name : 'Documents',
expanded : true,
children : [
{ name : 'Report.pdf', size : '2.1 MB', leaf : true },
{ name : 'Notes.txt', size : '12 KB', leaf : true }
]
}
]
});
targetElement.innerHTML = '<p>A basic TreeGrid with minimal configuration:</p>'; const tree = new TreeGrid({ appendTo : targetElement, height : 400, data : [ { id : 1, name : 'ABBA', iconCls : 'fa fa-users', born : null, expanded : true, children : [ { id : 11, name : 'Anni-Frid', born : 1945, iconCls : 'fa fa-user' }, { id : 12, name : 'Bjorn', born : 1945, iconCls : 'fa fa-user' }, { id : 13, name : 'Benny', born : 1946, iconCls : 'fa fa-user' }, { id : 14, name : 'Agnetha', born : 1950, iconCls : 'fa fa-user' } ] }, { id : 2, name : 'Roxette', iconCls : 'fa fa-users', born : null, children : [ { id : 21, name : 'Per', born : 1959, iconCls : 'fa fa-user' }, { id : 22, name : 'Marie', born : 1958, iconCls : 'fa fa-user' } ] } ], columns : [ { type : 'tree', field : 'name', text : 'Name', flex : 1 }, { type : 'number', field : 'born', text : 'Born', flex : 1, format : null } ] }); Useful configs and functions
| Member | Description |
|---|---|
| store | Tree store (must have tree: true) |
| columns | Must include one { type : 'tree' } column |
| toggleCollapse | Expand or collapse a node |
| collapse | Collapse a single node |
| expand | Expand a single node |
| expandAll | Expand all tree nodes |
| collapseAll | Collapse all tree nodes |
See also
- Grid - Non-tree grid
- TreeColumn - The required tree column type
- Tree - Tree feature handling expand/collapse
- Store - Data store (configure with
tree: true)
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
Preserve the grid's vertical scroll position when changesets are applied, as in the case of remote changes, or when stores are configured with syncDataOnLoad.
Has a corresponding runtime preserveScroll property.
-
Set
trueto add a border to this container's element. -
Custom style spec to add to element
Has a corresponding runtime style property.
-
Update fields if the record changes
-
Can be set to
trueto make a focus of a focusable encapsulating element relay focus down into a focusable child. This is normallyfalseto allow mousedown to begin text selection in Popups. -
Number of columns to use in a grid layout. Applied as
grid-template-columns: repeat(n, auto). Also applies theb-columnsCSS class to the container.Has a corresponding runtime gridColumns property.
-
Specify
trueto isolate record changes to this container and its ancestors. Prevents record updates from propagating up from here and also prevents record updates from parent from propagating down to us. -
Object to apply to elements dataset (each key will be used as a data-attribute on the element)
Has a corresponding runtime dataset property.
-
A createElement config object or HTML string from which to create the Widget's element.
Has a corresponding runtime element property.
-
Widget id, if not specified one will be generated. Also used for lookups through Widget.getById
Has a corresponding runtime id property.
-
Element (or element id) to insert this widget before. If provided, appendTo config is ignored.
Has a corresponding runtime insertBefore property.
-
Element (or element id) to append this widget element to, as a first child. If provided, appendTo config is ignored.
Has a corresponding runtime insertFirst property.
-
Internal listeners, that cannot be removed by the user.
-
Configure UI transitions for various actions in the grid.
- insertRecord : Boolean
Transition record insertions
- removeRecord : Boolean
Transition record removals
- toggleColumn : Boolean
Transition column visibility changes
- expandCollapseColumn : Boolean
Transition parent/group column expand/collapse
- toggleRegion : Boolean
Transition region expand/collapse
- toggleTreeNode : Boolean
Transition tree node expand/collapse
- toggleGroup : Boolean
Transition group expand/collapse
- filterRemoval : Booleanfalse
Transition row removals caused by filtering (under specific conditions)
Has a corresponding runtime transition property.
- insertRecord : Boolean
-
When this widget is a child of a Container, it will by default be participating in a flexbox layout. This config allows you to set this widget's align-self style.
Has a corresponding runtime alignSelf property.
-
Automatically set grids height to fit all rows (no scrolling in the grid). In general you should avoid using
autoHeight: true, since it will bypass Grids virtual rendering and render all rows at once, which in a larger grid is really bad for performance. -
Controls whether the panel is collapsed (the body of the panel is hidden while only the header is visible). Only valid if the panel is collapsible.
Has a corresponding runtime collapsed property.
-
Set to
trueto stretch the last column in a grid with all fixed width columns to fill extra available space if the grid's width is wider than the sum of all configured column widths. -
When this widget is a child of a Container, it will by default be participating in a flexbox layout. This config allows you to set this widget's flex style. This may be configured as a single number or a
<flex-grow> <flex-shrink> <flex-basis>format string. numeric-only values are interpreted as theflex-growvalue.Has a corresponding runtime flex property.
-
Widget's height, used to set element
style.height. Either specify a valid height string or a number, which will get 'px' appended. We recommend using CSS as the primary way to control height, but in some cases this config is convenient.Has a corresponding runtime height property.
-
Widget's margin. This may be configured as a single number or a
TRBLformat string. numeric-only values are interpreted as pixels.Has a corresponding runtime margin property.
-
Set to
falseto only measure cell contents when double-clicking the edge between column headers. -
A widgets weight determines its position among siblings when added to a Container. Higher weights go further down.
-
Widget's width, used to set element
style.width. Either specify a valid width string or a number, which will get 'px' appended. We recommend using CSS as the primary way to control width, but in some cases this config is convenient.Has a corresponding runtime width property.
-
A Mask config object, or a message to be shown when a store is performing a remote operation, or Crud Manager is loading data from the sever. Set to
nullto disable default load mask. -
Deprecated:
7.0.0 Deprecated
animateFilterRemovals. Usetransition.filterRemovalinsteadSet to
trueto animate row removals caused by filtering. -
Deprecated:
7.0.0 Deprecated
animateRemovingRows. Usetransition.removeRecordinsteadControls if removing and inserting rows should be animated. Set to
falseto prevent those animations, removing the related delays. -
Set to
falseto crop text in grid cells without ellipsis (...). When enabled, cells containing pure usedisplay : block, instead ofdisplay : flexto allow ellipsis to work. NOTE Only supported in browsers that support:has()CSS selectorHas a corresponding runtime cellEllipsis property.
-
Set to
falseto not show column lines. End result might be overruled by/differ between themes.Has a corresponding runtime columnLines property.
-
Event which is used to show context menus. Available options are: 'contextmenu', 'click', 'dblclick'.
-
When this Widget configuration is used in the Grid's RowExpander feature's
widgetconfig, provide the field on the expanded record to use for populating this widget's store (if applicable) -
Region to which columns are added when they have none specified
-
Set to
trueto destroy the store when the grid is destroyed. -
Set to
trueto not get a warning when using another base class than GridRowModel for your grid data. If you do, and would like to use the full feature set of the grid then include the fields from GridRowModel in your model definition. -
Deprecated:
7.3.0 Use
features : { stickyCells : true }insteadSet to
trueto enable the StickyCells feature, which pins cell content to the top of the grid while rows scroll off the top but remain visible. -
Set to
trueto listen for CTRL-Z (CMD-Z on Mac OS) keyboard event and trigger undo (redo when SHIFT is pressed). Only applicable when using a StateTrackingManager.Has a corresponding runtime enableUndoRedoKeys property.
-
Set to
trueto hide the column header elementsHas a corresponding runtime hideHeaders property.
-
Set to
trueto hide the Grid's horizontal scrollbar(s) -
A CSS class to add to hovered row elements
-
Set to
falseto disable localization of this object. -
Time in ms until a longpress is triggered
Has a corresponding runtime longPressTime property.
-
Grids change the
maskDefaultsto cover only theirbodyelement. -
Set to
trueto apply the default mask to the widget. Alternatively, this can be the mask message or a Mask config object. -
Grid monitors window resize by default.
-
Specify plugins (an array of classes) in config
Has a corresponding runtime plugins property.
-
True to preserve focused cell after loading new data
-
Specify
trueto preserve vertical scroll position after store actions that trigger arefreshevent, such as loading new data and filtering. -
Prevent tooltip from being displayed on touch devices. Useful for example for buttons that display a menu on click etc, since the tooltip would be displayed at the same time.
-
If you are rendering this widget to a shadow root inside a web component, set this config to the shadowRoot. If not inside a web component, set it to
document.body -
Set to
falseto not show row lines. End result might be overruled by/differ between themes.Has a corresponding runtime rowLines property.
-
Animation transition duration in milliseconds.
Has a corresponding runtime transitionDuration property.
-
This config is used with PanelCollapserOverlay to programmatically control the visibility of the panel's body. In this mode of collapse, the body of a collapsed panel is a floating overlay. Setting this config to
truewill show this element, whilefalsewill hide it. -
Configuration values for the ScrollManager class on initialization. Returns the ScrollManager at runtime.
Has a corresponding runtime scrollManager property.
-
The class to instantiate to use as the scrollable. Defaults to Scroller.
-
Set to
trueto allow text selection in the grid cells. Note, this cannot be used simultaneously with theRowReorderfeature. -
Set to
trueto not get a warning when calling getState when there is a column configured without anid. But the recommended action is to always configure columns with anidwhen using states. -
Deprecated:
7.0.0 Deprecated
animateTreeNodeToggle. Usetransition.toggleTreeNodeinsteadWhen the Tree feature is in use and the Store is a tree store, this config may be set to
trueto visually animate branch node expand and collapse operations.This is not supported in Scheduler and GanttHas a corresponding runtime animateTreeNodeToggle property.
-
The
bottomCSS absolute position for this widget. If specified, the widget is implicitly configured as positionable. -
Programmatic control over which column to start in when used in a grid layout.
Has a corresponding runtime column property.
-
The
inset-inline-startCSS absolute position for this widget. If specified, the widget is implicitly configured as positionable. -
Set this config to
falseto disable batching DOM updates on animation frames for this widget. This has the effect of synchronously updating the DOM when configs affecting the rendered DOM are modified. Depending on the situation, this could simplify code while increasing time spent updating the DOM. -
The
inset-inline-endCSS absolute position for this widget. If specified, the widget is implicitly configured as positionable. -
Programmatic control over how many columns to span when used in a grid layout.
Has a corresponding runtime span property.
-
The
topCSS absolute position for this widget. If specified, the widget is implicitly configured as positionable.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Delayable class, or subclass thereof.
-
Identifies an object as an instance of Events class, or subclass thereof.
-
Identifies an object as an instance of GridElementEvents class, or subclass thereof.
-
Identifies an object as an instance of GridFeatures class, or subclass thereof.
-
Identifies an object as an instance of GridResponsive class, or subclass thereof.
-
Identifies an object as an instance of GridSelection class, or subclass thereof.
-
Identifies an object as an instance of GridState class, or subclass thereof.
-
Identifies an object as an instance of GridSubGrids class, or subclass thereof.
-
Identifies an object as an instance of KeyMap class, or subclass thereof.
-
Identifies an object as an instance of LoadMaskable class, or subclass thereof.
-
Identifies an object as an instance of Localizable class, or subclass thereof.
-
Identifies an object as an instance of Pluggable class, or subclass thereof.
-
Identifies an object as an instance of RTL class, or subclass thereof.
-
Identifies an object as an instance of State class, or subclass thereof.
-
Identifies an object as an instance of Toolable class, or subclass thereof.
-
Identifies an object as an instance of TreeGrid class, or subclass thereof.
-
A class property getter for the default values of internal properties for this class.
-
Returns an array containing all existing Widgets. The returned array is generated by this call and is not an internal structure.
-
This property yields
trueif the currently focused element has been reached through other means than mouse click. If theactiveElementmatches:focus-visible. -
Get/set the recomposeAsync config for all widgets. Setting this value will set the config for all existing widgets and will be the default value for newly created widgets. Set this value to
nullto disable the default setting for new widgets while leaving existing widgets unaffected.Has a corresponding recomposeAsync config.
-
Preserve the grid's vertical scroll position when changesets are applied, as in the case of remote changes, or when stores are configured with syncDataOnLoad.
Has a corresponding preserveScroll config.
-
An object containing the SubGrid region instances, indexed by subGrid id ('locked', normal'...)
-
An empty array that can be used as a default value.
-
An empty object that can be used as a default value.
-
Identifies an object as an instance of Container class, or subclass thereof.
-
Identifies an object as an instance of Grid class, or subclass thereof.
-
Identifies an object as an instance of GridBase class, or subclass thereof.
-
Identifies an object as an instance of Panel class, or subclass thereof.
-
Identifies an object as an instance of TreeGrid class, or subclass thereof.
-
Identifies an object as an instance of Widget class, or subclass thereof.
-
Number of columns to use in a grid layout. Applied as
grid-template-columns: repeat(n, auto). Also applies theb-columnsCSS class to the container.Has a corresponding gridColumns config.
-
This property is
trueuntil the container's initialitemsconfig has been processed. This property is set tofalseby theupdateItemsmethod. -
Get widgets elements dataset or assign to it
Has a corresponding dataset config.
-
Get this widget's encapsulating HTMLElement, which is created along with the widget but added to DOM at render time.
Has a corresponding element config.
-
Get this widget's primary focus holding element if this widget is itself focusable, or contains focusable widgets.
-
Returns an object describing the focus and keyboard navigation aspects of this widget's focusElement.
-
Returns this widget's focusElement if that element can currently be given focus (e.g., this widget is not disabled, or hidden).
-
This property is set to
trueafter processing the initial paint for the widget. It remainsfalseduring the initial paint. The intended use for this flag is to avoid processing that will be handled by the first paint (similar to not firing events during the widget's initial configuration). If this field istrue, the initial paint has already taken place, otherwise, it has yet to run. This field differs fromisPaintedwhich checks that the widget's element is attached to the DOM. -
Get/set widgets id
Has a corresponding id config.
-
Element (or element id) to insert this widget before. If provided, appendTo config is ignored.
Has a corresponding insertBefore config.
-
Element (or element id) to append this widget element to, as a first child. If provided, appendTo config is ignored.
Has a corresponding insertFirst config.
-
The child element which scrolls if any. This means the element used by the scrollable.
-
Returns the
DomClassListfor this widget's class. This object should not be mutated. -
Get/set widgets elements style. The setter accepts a cssText string or a style config object, the getter always returns a CSSStyleDeclaration
Has a corresponding style config.
-
Returns content height calculated from row manager
-
Override to attach the keyMap keydown event listener to something else than this.element
-
Override to make keyMap resolve subcomponent actions to something else than this.features.
-
Get/set this widget's
align-selfflexbox setting. This may be set to modify how this widget is aligned within the cross axis of a flexbox layout container.Has a corresponding alignSelf config.
-
Body height
-
Controls whether the panel is collapsed (the body of the panel is hidden while only the header is visible). Only valid if the panel is collapsible.
Has a corresponding collapsed config.
-
This property is
trueif the panel is currently collapsing. -
This property is
trueif the panel is currently either collapsing or expanding. -
This property is
trueif the panel is currently expanding. -
Header height
-
Get element's
offsetHeightor sets itsstyle.height, or specified height if element no created yet.Has a corresponding height config.
-
Get element's margin property. This may be configured as a single number or a
TRBLformat string. numeric-only values are interpreted as pixels.Has a corresponding margin config.
-
Accessor to the Scroller which can be used to both set and read scroll information.
Has a corresponding scrollable config.
-
Get elements
offsetWidthor sets itsstyle.width, or specified width if element not created yet.Has a corresponding width config.
-
Returns a copy of the full configuration which was used to configure this object.
-
This property is set to
truebefore theconstructorreturns. -
This property is set to
trueon entry to the destroy method. It remains on the objects after returning fromdestroy(). If isDestroyed istrue, this property will also betrue, so there is no need to test for both (for example,comp.isDestroying || comp.isDestroyed). -
Get id assigned by user (not generated id)
-
Set to
falseto crop text in grid cells without ellipsis (...). When enabled, cells containing pure usedisplay : block, instead ofdisplay : flexto allow ellipsis to work. NOTE Only supported in browsers that support:has()CSS selectorHas a corresponding cellEllipsis config.
-
Set to
falseto not show column lines. End result might be overruled by/differ between themes.Has a corresponding columnLines config.
-
Get/set element's disabled state. Set to
'inert'to also set theinertDOM attribute.Has a corresponding disabled config.
-
Set to
trueto listen for CTRL-Z (CMD-Z on Mac OS) keyboard event and trigger undo (redo when SHIFT is pressed). Only applicable when using a StateTrackingManager.Has a corresponding enableUndoRedoKeys config.
-
true if no id was set, will use generated id instead (widget1, ...). Toggle automatically on creation
-
Set to
trueto hide the column header elementsHas a corresponding hideHeaders config.
-
The currently hovered grid cell
-
Get the global LocaleHelper
-
Get the global LocaleManager
-
Time in ms until a longpress is triggered
Has a corresponding longPressTime config.
-
Map of applied plugins
Has a corresponding plugins config.
-
Get currently used responsive level (as string)
-
Set to
falseto not show row lines. End result might be overruled by/differ between themes.Has a corresponding rowLines config.
-
Animation transition duration in milliseconds.
Has a corresponding transitionDuration config.
-
Get the Row currently displayed furthest down.
-
Get the topmost visible grid row
-
Get the last visible grid row
-
Get the Row that is currently displayed at top.
-
Configuration values for the ScrollManager class on initialization. Returns the ScrollManager at runtime.
Has a corresponding scrollManager config.
-
In cell selection mode, this will get the cell selector for the (last) selected cell. Set to an available cell selector to select only that cell. Or use selectCell() instead.
-
CSS selector for the currently selected cell. Format is "[data-index=index] [data-column-id=column]".
-
In cell selection mode, this will get the cell selectors for all selected cells. Set to an array of available cell selectors. Or use selectCells() instead.
-
The last selected record. Set to select a row or use Grid#selectRow. Set to null to deselect all
-
Returns
trueif this instance implements the State interface. -
Returns
trueif this instance is ready to participate in state activities. -
Gets or sets grid's state. Check out GridState mixin for details.
-
Returns an object whose truthy keys are the config properties to include in this object's state.
-
Deprecated:
7.0.0 Deprecated
animateTreeNodeToggle. Usetransition.toggleTreeNodeinsteadWhen the Tree feature is in use and the Store is a tree store, this config may be set to
trueto visually animate branch node expand and collapse operations.This is not supported in Scheduler and GanttHas a corresponding animateTreeNodeToggle config.
-
Determines visibility by checking if the Widget is hidden, or any ancestor is hidden and that it has an element which is visible in the DOM
-
Programmatic control over which column to start in when used in a grid layout.
Has a corresponding column config.
-
Returns
trueif this class usescompose()to render itself. -
This widget's twin that is placed in an overflow menu when this widget has been hidden by its owner, typically a Toolbar due to overflow. The
overflowTwinis created lazily by ensureOverflowTwin. -
Programmatic control over how many columns to span when used in a grid layout.
Has a corresponding span config.
-
Get this Widget's next sibling in the parent Container, or, if not in a Container, the next sibling widget in the same parentElement.
-
Get this Widget's parent when used as a child in a Container,
-
Get this Widget's previous sibling in the parent Container, or, if not in a Container, the previous sibling widget in the same parentElement.
-
An object which contains a map of descendant widgets keyed by their ref. All descendant widgets will be available in the
widgetMap.
Functions
Functions are methods available for calling on the class-
This optional class method is called when a class is mixed in using the mixin() method.
-
Clear caches, forces all calls to fromCache to requery dom. Called on render/rerender.
-
Internal function used to hook destroy() calls when using thisObj
-
Internal function used restore hooked destroy() calls when using thisObj
-
Auto detaches listeners registered from start, if set as detachable
-
Init listeners for a bunch of dom events. All events are handled by handleEvent().
-
Internal function used to run a callback function after an event is triggered
-
Removes all listeners registered to this object by the application.
-
Remember scroll position when store is about to apply a changeset
-
Creates a fake subgrid with one row and measures its height. Result is used as rowHeight.
-
Handler for global theme change event (triggered by shared.js). Remeasures row height.
-
Recalculates virtual scrollbars widths and scrollWidth
-
Restore scroll position. Go to the topmost row formerly in the view that is still present in the dataset.
-
Adds extra classes to the Grid element after it's been configured. Also iterates through features, thus ensuring they have been initialized.
-
Used internally to get a range of cell selectors from a start selector to an end selector.
-
Collapse all groups. This function is exposed on Grid and can thus be called as
grid.collapseAll()Added by the Group feature, only available when that feature is enabled.
-
Expand all groups. This function is exposed on Grid and can thus be called as
grid.expandAll()Added by the Group feature, only available when that feature is enabled.
-
Called on keyMapElement keyDown
-
Called by the Base constructor after all configs have been applied.
-
Find closes bigger level, aka level we want to use.
-
Resumes CSS transitions after a row / event has been updated
-
unmaskBody( ) Grid
Hide the load mask.
-
Collapse the panel.
-
Expand the panel.
-
Template method which may be implemented in subclasses to initialize any plugins. This method is empty in the
Pluggablebase class. -
Rerenders all grid headers
-
Rerenders the grids rows, headers and footers, completely replacing all row elements with new ones
-
renderRows( ) Grid
Rerenders all grid rows, completely replacing all row elements with new ones
-
Scroll syncing for normal headers & grid + triggers virtual rendering for vertical scroll
Triggers: scroll
-
Triggered from Grid view when the store changes. This might happen if store events are batched and then resumed. Deselects all records which have been removed.
-
Triggered from Grid view when the id of a record has changed. Update the collection indices.
-
Triggered from Grid view when records get removed from the store. Deselects all records which have been removed.
-
Triggered from Grid view when all records get removed from the store. Deselects all records.
-
This selects all rows. If store is filtered, this will merge the selection of all visible rows with any selection made prior to filtering.
-
Hooks up data store listeners
-
Refreshes rows when data is added to the store
-
Hides load mask after a load request ends either in success or failure
-
Shows a load mask while the connected store is loading
-
Responds to exceptions signalled by the store
-
Rerenders a cell if a record is updated in the store
-
Refreshes the store tree grouping by re-applying the current transformation.
// Refresh groups grid.refreshGroups();Added by the TreeGroup feature, only available when that feature is enabled.
-
This method is called following an update to the widget's rendered DOM.
-
Disable the widget
-
Enable the widget
-
Unmask the widget
-
Sets widths and heights for headers, rows and other parts of the grid as needed
Events
Events are triggered for certain actions in this class and can be listened for to react to those actions in your code-
Fired when a FillHandle drag operation is aborted.
Added by the FillHandle feature, only available when that feature is enabled.
-
This event is fired after a widget's elements have been synchronized due to a direct or indirect call to recompose, if this results in some change to the widget's rendered DOM elements.
-
Fires when un-splitting the Grid.
Added by the Split feature, only available when that feature is enabled.
Event handlers
Event handlers are callbacks called as a result of certain actions in this class-
Called when a FillHandle drag operation is aborted.
Added by the FillHandle feature, only available when that feature is enabled.
-
This event is called after a widget's elements have been synchronized due to a direct or indirect call to recompose, if this results in some change to the widget's rendered DOM elements.
-
Called when un-splitting the Grid.
Added by the Split feature, only available when that feature is enabled.
Source path
Grid/view/TreeGrid.js- AI
- CellCopyPaste
- CellEdit
- CellMenu
- CellTooltip
- Charts
- ColumnAutoWidth
- ColumnDragToolbar
- ColumnPicker
- ColumnRename
- ColumnReorder
- ColumnResize
- FillHandle
- Filter
- FilterBar
- Group
- GroupSummary
- HeaderMenu
- LockRows
- MergeCells
- PinColumns
- QuickFind
- RegionResize
- RowCopyPaste
- RowEdit
- RowExpander
- RowReorder
- RowResize
- Search
- Sort
- Split
- StickyCells
- Stripe
- Summary
- Tree
- TreeGroup
- AIFilter
- ExcelExporter
- FileDrop
- PdfExport