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:
- I set the
item
property of itsrepeating_panel
; - I set some properties in the
tag
property of itsrepeating_panel
; - I add an
event_handler
to itsrepeating_panel
- I add two list comprehensions based of its columns to its
tag
property; - I raise the init_events for the routing_context (routing dependency);
- On the
query_changed
event:- change its
auto_header
property; - toggle a css class to the
repeating_panel
usinganvil.js.get_dom_node
; - change it’s columns using one of the previously set properties on it’s
tag
; - raise an event on it’s children
- change its
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.