-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_grid() doesn't work properly when adding/deleting rows (async delayed) #38
Comments
I get a similar problem but for me it's not an issue of waiting 1 or 2 seconds. I think it's more related to displaying the grid again before accessing the underlying dataframe. If I update the data for the grid and then request g.grid_data_out['grid'], the grid is unchanged. I need to display the grid in a jupyter cell again after updating it. Then when I run g.grid_data_out['grid'] I see the updated results. |
it would be great if this could be fixed as adding and deleting rows as a crucial part of many apps |
I have noticed that the grid gets updated if you run get_grid() in one cell and then use grid_data_out['grid'] to request the grid in the next one (does not seem to work if you do both in the same cell). |
Yes this is the same issue!! hopefully they'll fix it :) |
anything on this issue? |
We could also sync the grid on the menu action, like what happens on the built-in edit: g = Grid(
...,
js_helpers_custom="""
helpersCustom = {
syncGrid() {
view.model.set("_export_mode", "grid");
view.model.trigger('change:_counter_update_data');
}
}
""", and call it from the menu items: ...
return [
{{
name: 'Delete Row(s)',
action: function () {{
...
params.api.applyTransaction({{ remove: selectedRows }});
helpers.syncGrid();
}},
}},
... Whole example: import pandas as pd
import numpy as np
from ipyaggrid import Grid
df = pd.DataFrame([{'a': i, 'b': i+1, 'c':i+2} for i in range(10)])
g = Grid(
grid_data=df,
grid_options={
'columnDefs': [{'field': col} for col in df],
'enableSorting': True,
'enableFilter': True,
'enableColResize': True,
'enableRangeSelection': True,
'getContextMenuItems': """
function (params) {
return [{
name: 'Delete Row(s)',
action: function () {
let selectedRows = params.api.getSelectedRows();
params.api.applyTransaction({ remove: selectedRows });
helpers.syncGrid();
},
}];
}
""",
'rowSelection': 'multiple'
},
theme='ag-theme-balham',
show_toggle_edit=True,
sync_on_edit=True,
js_helpers_custom="""
console.log('view', view.model)
helpersCustom = {
syncGrid() {
view.model.set("_export_mode", "grid");
view.model.trigger('change:_counter_update_data');
}
}
""",
)
g Also, holding shift when right-clicking prevents the lan contect menu from showing. Would this work for y'all? |
Hello @mariobuikhuizen I have tested it and works for me. Thanks a lot for this example |
@mariobuikhuizen If I update the grid using
This is a very common use-case which is not currently possible to achieve safely due to the async behaviour Probably the best thing would be to have a parameter that governs the async/sync behaviour of the grid updates. See below: Right after creation it throws an error because
|
hello @mariobuikhuizen any update on this by any chance? |
Below a simple reproducible example:
get_add_delete_row_fn
that adds 3 options to the right click context menu for deleting rows and adding rows above or belowgrid.get_grid()
and displaygrid.grid_data_out['grid']
the output is not updated right away (it still shows the data previous to deletion/addition)grid.grid_data_out['grid']
the data is updated correctly.this is the function to add the the context menu the option for deleting and inserting rows
This is the grid creation
Now to reproduce the example could you please:
(Tip: if you don't see the menu it's because it's covered by the jupyterlab menu, just scroll with the mouse wheel and it should appear)
You will see that the data is not updated, but the cell is executed
Now please wait 1 or 2 seconds and execute only this
g.grid_data_out['grid']
in another cell.Now the data is updated.
Finally try to rerender the grid in another cell and you'll see that the changes are lost
The text was updated successfully, but these errors were encountered: