TreeGrid mode
The TreeGrid mode of the Grid component is available in the PRO version only.
TreeGrid mode of the Grid component allows showing the nested tabular data.

Initialization
To initialize Grid in the TreeGrid mode, make use of the type: "tree" configuration option.
const Grid = new dhx.Grid("grid_container", {
type: "tree",
columns: [
{ id: "name", header: [{ text: "Name" }], gravity: 1.5 },
{ id: "native", type: "string", header: [{ text: "Native name" }], gravity: 1.5 },
{ id: "capital", type: "string", header: [{ text: "Capital" }] },
{ id: "currency", type: "string", header: [{ text: "Currency" }] }
],
data: dataset,
autoWidth: true
});
Configuration
Grid in the TreeGrid mode uses all the same configuration options available in the API of the default Grid.
There is also a set of properties you can provide for Grid in the TreeGrid mode to optimize its configuration for your needs.
Collapsed mode
To initialize Grid in the TreeGrid mode in the collapsed state, use the collapsed property:
const grid = new dhx.Grid("grid_container", {
type: "tree",
columns: [
// columns config
],
data: dataset,
collapsed: true
});
Related sample: Grid (TreeGrid). Collapsed mode
Expanding collapsed rows on drag-n-drop
If you have collapsed rows in your Grid in the TreeGrid mode, they will expand automatically when you move the mouse pointer over them during drag-n-drop. To disable this functionality, set the dragExpand property to false:
const grid = new dhx.Grid("grid_container", {
type: "tree",
columns: [
// columns config
],
dragItem: "row",
dragExpand: false,
data: dataset
});
Related sample: Grid (TreeGrid). Multiselection and drag-n-drop
Defining the id of the root parent
To define the id of the root parent, use the rootParent configuration property:
const grid = new dhx.Grid("grid_container", {
type: "tree",
rootParent: "root",
columns: [
{ width: 340, id: "name", header: [{ text: "Name" }] },
{ width: 340, id: "native", type: "string", header: [{ text: "Native name" }] },
{ width: 260, id: "capital", type: "string", header: [{ text: "Capital" }] },
{ width: 260, id: "currency", type: "string", header: [{ text: "Currency" }] }
],
data: dataset
});
When Grid is initialized in the TreeGrid mode, the root parent takes the id of the Grid container by default. If the id of the container is set to null or defined as an HTML element, the value of the root parent will be auto-generated.
Data loading
There are several simple ways of loading data into Grid in the TreeGrid mode:
First, you need to prepare a data set that will be loaded into Grid in the TreeGrid mode.
Preparing data set
Grid in the TreeGrid mode expects loaded data in the JSON format.
Please note that if you specify the id fields in the tree collection, their values should be unique. You can also omit the id fields in the tree collection. In this case they will be generated automatically.
Here is an example of an appropriate data set:
const dataset = [
{
"id": 0,
"a": 1,
"b": "Linwood Long long long",
"c": "Petersen",
"d": "Dahlgreen Place"
},
{
"id": 1,
"parent": 0,
"a": 2,
"b": "Edenburg",
"c": "Agnes",
"d": "Gem Street"
},
// more columns
];
Each object in the data set contains configuration of a grid row. The structure of a row is rather flexible. It may include:
| rowId | (string | number) optional, the id of a row. In case you haven't specified ids of rows, they will be auto-generated |
| parent | (string | number) the ID of the parent row |
| columnContent | (string | number) content of a column as key:value pairs, where key is the id of a column and value is any content you want to add into the column |
Loading data on Grid initialization
You can specify data you want to load into Grid in the TreeGrid mode on the initialization stage. Make use of the data configuration property, as in:
const grid = new dhx.Grid("grid_container", {
type: "tree",
columns: [
// columns config
],
data: dataset
});
Related sample: Grid (TreeGrid). Initialization with config.data
Loading data after initialization
There are two ways to load data into Grid in the TreeGrid mode after its initialization: