Replies: 2 comments
-
|
Good questions! Let me answer them one by one. 1. Why was Because that's AG Grid's own data format, not really a NiceGUI design decision: 2. What is NiceGUI itself never interprets it.
The only place where NiceGUI writes to it is 3. Is there any drawback in letting Yes, one big caveat: any of the updates listed above will silently reset the grid to the stale Since you keep your own ID-keyed representation anyway, the simplest robust pattern is probably to treat it as the single source of truth and regenerate the list from it after every change (or batch of changes): grid.options["rowData"] = list(my_rows.values())This is just an O(n) copy of references, so it's cheap even for frequent updates, covers insertions and deletions without any extra bookkeeping, and an unexpected re-render then shows correct data instead of stale data. Unrelated tip in case you don't use it yet: the grid = ui.aggrid({
...
':getRowId': '(params) => String(params.data.index)',
})With this, |
Beta Was this translation helpful? Give feedback.
-
|
This is very useful. Thank you! Regarding 1., the 1:1 mirror makes perfect sense, of course. It's a bit surprising that AG Grid stores the data as list-like, but the transactions, at least, seemingly operate more dict-like.
Regarding the actual problem, I was thinking about exactly this: grid.options["rowData"] = list(my_rows.values())as well. But, in my case, it would look more like this: grid.options["rowData"] = df.to_dict("records")Which is not just a copy of references but a full copy of the data. I could just take this hit for simplicity. As long as the table is not huge, it should not be an issue. But if the table was actually huge, it probably would be better anyway to stream the data only per page or similar optimizations (which I don't consider in scope at the moment). Alternatively, I might actually get simpler code by making it worse: I could keep three sets of data in sync: the dataframe, I can even see a third option: I could run |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am tinkering with a project where I have a dataframe that gets updated by user interactions and the current version should be displayed using an
ui.aggrid.I find myself struggling with the data representation in
grid.options["rowData"].Since this is a list, equivalent to the output of
df.to_dict("records"), I need to convert between the "row ID" (what dataframes call "index") and an integer list index.I do something like this (wrapped away in a function, of course) in many place:
I am also using
run_grid_method("applyTransaction", ...), to sync to the client side without re-draw. This is also (implicitly) based around the row ID, except for insertion viaaddwith anaddIndex, but there's really no other way to deal with inserts, I guess.If I am not mistaken, the representation equivalent to
df.to_dict("index")would make my life/code far simpler.So, I have two questions:
df.to_dict("records")chosen?grid.options["rowData"]really used for?The first one is just because I am curious. I would prefer to switch to
df.to_dict("index"), but this would break everyone's code, which is clearly a bad idea. Unless someone has a solution where the representation can be configurable?The second is what could actually help me: I am anyway handling the server-side data myself. So, at the moment, I am keeping my own and
ui.aggrid's server-side data in sync with the client-side data viaapplyTransaction. I am wondering if I could just stop doing that and only have my own representation synced viaapplyTransaction. Basically, I initialize from my server-side data and then apply deltas to the client.So, the more concrete version of 2. would be:
grid.options["rowData"]go out of sync in such a scenario?Beta Was this translation helpful? Give feedback.
All reactions