You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After filtering, the first row of filtered data will always have row index 0. Thus if I select the first row then filter the row and then select the first row, it will overwrite the previous selected data on index 0.
I am using this code below:
import justpy as jp
import pandas as pd
wm_df = pd.read_csv('https://elimintz.github.io/women_majors.csv').round(2)
def row_selected4(self, msg):
print(msg.selected, msg)
wp = msg.page
if msg.selected:
wp.selected_rows[msg.rowIndex] = msg.data
else:
wp.selected_rows.pop(msg.rowIndex)
s = f'Selected rows {sorted(list(wp.selected_rows.keys()))}'
for i in sorted(wp.selected_rows):
s = f'{s}\n Row {i} Data: {wp.selected_rows[i]}'
if wp.selected_rows:
wp.rows_div.text = s
else:
wp.rows_div.text = 'No row selected'
def grid_test13():
wp = jp.WebPage()
wp.selected_rows = {} # Dictionary holding selected rows
grid = jp.AgGrid(a=wp, style='height: 200px; width: 300px; margin: 0.25em')
grid.load_pandas_frame(wm_df)
grid.options.columnDefs[0].checkboxSelection = True
grid.options.defaultColDef.filter = True
grid.options.defaultColDef.sortable = True
grid.options.rowSelection = 'multiple'
grid.on('rowSelected', row_selected4)
wp.rows_div = jp.Pre(text='Data will go here when you select rows', classes='border text-lg', a=wp)
return wp
jp.justpy(grid_test13)
for now, I work around it by using not the row index as the dictionary index but another columns value that will not change even if the row is filtered. say for example:
df['row_number'] = df.reset_index().index
then I use the row_number column in event handler:
The id of the row object (node) is now included in the event message.
The example grid_test13 is adjusted accordingly and now also works correctly if the grid is filtered.
See
After filtering, the first row of filtered data will always have row index 0. Thus if I select the first row then filter the row and then select the first row, it will overwrite the previous selected data on index 0.
I am using this code below:
for now, I work around it by using not the row index as the dictionary index but another columns value that will not change even if the row is filtered. say for example:
df['row_number'] = df.reset_index().index
then I use the row_number column in event handler:
If possible, we should use row node id provided by ag grid itself:
https://www.ag-grid.com/react-data-grid/row-object/#reference-rowNodeAttributes-id
The text was updated successfully, but these errors were encountered: