This page covers a non-latest version of Handsontable.
# Row parent-child
WARNING
Sorting and filtering features don't work with the parent-child structure.
# Overview
The Nested Rows plugin extends Handsontable, adding new functionality that displays nested structures in a two-dimensional data table.
# Quick Setup
To enable the plugin, simply set the nestedRows
option to true
.
const hot = new Handsontable(container, {
nestedRows: true,
});
Note that using all the functionalities provided by the plugin requires enabling the row headers and the Handsontable context menu. To do this set rowHeaders
and contextMenu
to true
. The collapse / expand buttons are located in the row headers, and the row modification options add row, insert child, etc., are in the Context Menu.
# Preparing the data source
The data source must have a specific structure to be used with the Nested Rows plugin.
The plugin requires the data source to be an array of objects. Each object in the array represents a single 0-level entry. 0-level refers to an entry, which is not a child of any other entry.
If an entry has any child entries, they need to be declared again as an array of objects. To assign them to a row, create a __children
property in the parent element.
Here's an example:
In the example above, we’ve created a data object consisting of 2016’s Grammy nominees of the “Rock” genre. Each 0-level entry declares a category, while their children declare nominees - assigned under the __children
properties.
TIP
Note that the first 0-level object in the array needs to have all columns defined to display the table properly. They can be declared as null
or an empty string ''
, but they need to be defined. This is optional for the other objects.
# User interface
The Nested Rows plugin's user interface is placed in the row headers and the Handsontable’s context menu.
# Row headers
Each parent row header contains a +
/-
button. It is used to collapse or expand its child rows.
The child row headers have a bigger indentation, to enable the user to clearly recognize the child and parent elements.
# Context Menu
The context menu has been extended with a few Nested Rows related options, such as:
- Insert child row
- Detach from parent
The “Insert row above” and “Insert row below” options were modified to work properly with the nested data structure.
# Related articles
# Related guides
# Related API reference
- Configuration options:
- Core methods:
- Hooks:
- Plugins:
← Row header Row hiding →