[GH #7017] Nested Rows Not Rendering When Dynamically Setting Data

Tags: #<Tag:0x00007f51b991cdc0> #<Tag:0x00007f51b991cbb8>

### Issue: Nested Rows Not Rendering When Dynamically Setting Data

Problem Description:

I am trying to render a Handsontable instance with nested rows . Here’s the issue I’m encountering:

  1. When I set the data property dynamically using hotInstance.loadData(nestedData) or by first setting the data and then calling .updateSettings({ nestedRows: true }) , the rows don’t render as expected. The output only shows the parent row without any nested child rows (see attached screenshot).
  2. However, when I hardcode the data directly into the data property of the <HotTable /> component, everything renders perfectly, including the __children rows.

My Setup:

I’m using the following properties:

  • nestedRows: true
  • rowHeaders , colHeaders , and contextMenu enabled.

Code Snippet:

        const nestedData = [
      {
        category: 'Best Rock Performance',
        artist: null,
        title: null,
        label: null,
        __children: [
          { title: "Don't Wanna Fight", artist: 'Alabama Shakes', label: 'ATO Records' },
          { title: 'What Kind Of Man', artist: 'Florence & The Machine', label: 'Republic' },
          { title: 'Something From Nothing', artist: 'Foo Fighters', label: 'RCA Records' },
          { title: "Ex's & Oh's", artist: 'Elle King', label: 'RCA Records' },
          { title: 'Moaning Lisa Smile', artist: 'Wolf Alice', label: 'RCA Records/Dirty Hit' },
        ],
      },
    ];

    useEffect(() => {
      if (hotTableRef.current) {
        const hotInstance = hotTableRef.current.hotInstance;
        hotInstance.loadData(nestedData); // Data gets loaded but nested rows do not render
      }
    }, []);

Questions:

  1. Why does dynamically setting data with loadData() not render the nested rows, even though the same data works when hardcoded into the data property?
  2. Is there an additional step required to make nested rows work dynamically? Should I explicitly call updateSettings with nestedRows: true after loading the data?

Any guidance on dynamically setting data for nested rows would be much appreciated. Thank you!

Attachments:

Hi @dhairyasehgal2307

Thank you for contacting us. This issue is connected to the problem that is already reported here: https://github.com/handsontable/handsontable/issues/7017

To make this structure work correctly the dataset and option nestedRows has to be set at the same time. You can check your console as you are probably also getting the error saying that the data structure is incorrect. That’s because the plugin is initialized before the data is set. Unfortunately there are no workarounds at the moment, as even trying to set it using updateSettings will also not work. More details are described in the issue I attached.