[Fixed] DataGrid auto_header toggling not functioning correctly

What I’m trying to do:
Programatically turn the auto_header on and off on a DataGrid.

I tried creating a MVE, but it worked correctly on it.

The form renders the grid correctly on it’s initialization (visible or not, it works both ways).

When I set data_grid.auto_header = False for the first time (on or after initialization) it will work, however when I try to set data_grid.auto_header = True, nothing happens.

Things that I intend to do to the grid in the initialization:

  1. I set the item property of its repeating_panel;
  2. I set some properties in the tag property of its repeating_panel;
  3. I add an event_handler to its repeating_panel
  4. I add two list comprehensions based of its columns to its tag property;
  5. I raise the init_events for the routing_context (routing dependency);
  6. On the query_changed event:
    1. change its auto_header property;
    2. toggle a css class to the repeating_panel using anvil.js.get_dom_node;
    3. change it’s columns using one of the previously set properties on it’s tag;
    4. raise an event on it’s children

What I’ve identified:
When I set it to False, it removes the row from the dom. When I set it to True, normally it would add it again (as I tested with other grids in other apps), but it doesn’t. The value of data_grid.auto_header is True, however. On other data-grids this works fine.

If the repeating-panel has no items, then it works perfectly. As soon as I add items to it, it stops working. When trying it on other data-grids that have items, the behaviour is like normally expected.

If I try to toggle the auto_header using data_grid.auto_header = not data_grid.auto_header it does not work at first, but after a few tries it starts working. Once it starts working, then it works always.

Once it’s False, it’s to need 6-7 tries (each try going first to False and then to True again) to start working. The number of rows in the grid is 6 (not counting the header).

Right now I’m revisiting the associated RowTemplate, since it looks like the items trigger the problem, but if anyone can help with ideas of what could be affecting this (even though I’m not sharing an MVE), I would thank immensely.

Edit 1: I tried to put less items in the grid and that reduced the number of times the toggling was needed. With 2 items, it needed 2 tries. So it is related…

Edit 2: It seems this happens because I have another Data Grid inside the DataGrid. I’ll try to make a MVE using this information.

Edit 3: Ok! I successfully created a MVE demo:

You can see in this demo that each time it toggles, it’s actually first toggling the data grids inside the rows before going back to the correct one.

Edit 4: Also, it appears to be permanently removing the auto_header and columns for the inner data grids.

1 Like

Thanks for reporting, and putting together the clone link
This looks like an issue with nested data grids
We’ll get that fixed

2 Likes

Just as an extra info: I did a workaround for now that seems to work:
Before changing the auto_header value I remove the inner grid from it’s parent and then readd it afterwards. Since the grid isn’t in the dom while removing the auto_header, it seems to work.

I remember noticing something like this while changing the columns of a data grid programatically while having a data-row-panel added to the data-grid, but don’t know if its the same problem.

1 Like