DevExtreme React - Use Hierarchical Data

For an example of hierarchical data, see the following code snippet.

JavaScript
  • var hierarchicalData = [{
  • id: '1',
  • text: 'Fruits',
  • items: [
  • { id: '1_1', text: 'Apples' },
  • { id: '1_2', text: 'Oranges' }
  • ]
  • }, {
  • id: '2',
  • text: 'Vegetables',
  • items: [
  • { id: '2_1', text: 'Cucumbers' },
  • { id: '2_2', text: 'Tomatoes' }
  • ]
  • }];

View Demo

As you can see, all items in a hierarchical data source have the id and text fields, and items with children have the items field. Those are conventional field names defined by the Default Item Template pattern. To use other names, change the keyExpr, displayExpr and itemsExpr options, respectively.

Frequently, the id of an item is also its text. In this case, set both the keyExpr and displayExpr options to a single value.

See Also