jupyter-widgets / ipydatagrid

Fast Datagrid widget for the Jupyter Notebook and JupyterLab
BSD 3-Clause "New" or "Revised" License
579 stars 51 forks source link

select function not trigger observe #478

Open CnBDM-Su opened 9 months ago

CnBDM-Su commented 9 months ago

The selection function cannot trigger traitlets observe.

I am using select(), trying to realize control table both with manual and with function. The observe function of table is only triggered when click, but not after select() function.

Do you know how to trigger it?

Example: def func(change): ... datagrid.observe(func, name=['selections']) datagrid.select(row1=rows,column1=1,row2=rows, column2=1)

*func should be run based on new selections, but not.

mmilch01 commented 6 months ago

I am also interested in resolving this. When onclick function is triggered, the selection returned in the field .selected_cell_values shows previous selection. I found no way so far to track current selection once it changed.

willysttm commented 1 month ago

I have the same problem. A solution would be great! Here is a minimal example (no print after table.select):

import pandas as pd
import ipywidgets as widgets
from ipydatagrid import DataGrid

df = pd.DataFrame(
    {
    'A': [10, 20, 30, 40],
    'B': [50, 60, 70, 80]
    }
)

table = DataGrid(df, selection_mode='row')

def update_on_selection(change):
    print("selection changed:", change['new'])

table.observe(update_on_selection, names='selections')

display(table)

table.select(0, 0)
basiekjusz commented 1 month ago

I'm facing the same issue. A solve or workaround would be great.