Question for option 1 "Change data before load to store."
Is there a way to manipulate the data retrieved if we use store autoLoad feature?
In our project code, we pull data similar to the following.
If I want to expand a selected node in store change event, how can I do that?
I tried record.toggleCollapse or source.grid.toggleCollapse, but returns undefined.
Please see the code below.
Hi, the solution is not valid. You are changing node state while rendering that causes collisions. It won't be working this way.
There are 2 options:
Change data before load to store.
You need to get state from localStore, change expanded field value for all required records and load/set data to store after that. You can add your code into useGridConfig method above return object.
Change state after render complete.
You need to subscribe on event that triggers when rendering finished (as example https://bryntum.com/products/grid/docs/api/Core/widget/Widget#event-paint ) and apply state to records after rendering. Of course, in this case nodes will "jump" because original state and applied state will be different.
In 2 words, expanded/collapse state of nodes - is data layer level. So I suggest you to work with it on data level. I am not sure if you used static data in your real app, but in any case there is a way to apply state on data before rendering.
I tried the paint event, but it works only on the first item of the state. Succeeding states are not applied to grid.
Sample state:
[
{id: 2, expanded: true}, //only this is applied to grid
{id: 3, expanded: true} //not applied to grid
]
Yes, it works only for first record that you change state in a loop.
In your first solution using change event, you are trying to do same as on paint event - call toggleCollapse, but the idea was to change data before in loaded into the store on data level. So nothing new in that solution.
Solution in "additional updates" section contains not valid code.
First, you set record.expanded in a loop, but record is a property of a method and never change in a loop. So you might be was about row.expanded = true. But it also not valid, expanded field is readOnly.