quantopian / qgrid

An interactive grid for sorting, filtering, and editing DataFrames in Jupyter notebooks
Apache License 2.0
3.03k stars 424 forks source link

filter_changed is not recognised in .on() #384

Open HariniMadhi opened 1 year ago

HariniMadhi commented 1 year ago

qgrid_widget.on doesn't recognixe 'filter_changed', 'filter_dropdown_shown'.

To replicate,

import qgrid
import pandas as pd
def func(change, a):
    print(change, a)

df = pd.DataFrame({'Highlight': ['1', '1', '0', '0', '1', '0', '1', '1', '1', '1', '0', '1', '1', '1', '0'], 'Letters' :['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o']})
qgrid_widget = qgrid.show_grid(df)
qgrid_widget.on('filter_changed', func)
qgrid_widget

The need for this: To use the filter functionality within the program (not just as a User Interface feature). I have used the below code to defaultly show the rows that have Highlight = 1.

qgrid_widget._handle_qgrid_msg_helper({'type':'show_filter_dropdown', 'field':'Highlight', 'search_val':'1'})
qgrid_widget._handle_qgrid_msg_helper({'field':'Highlight', 'filter_info':{'field':'Highlight', 'selected':[0], 'type':'text', 'excluded':[]}, 'type':'change_filter'})

But this reduces the size of the table, and when I use the filter to include the 0 as well, the dataframe populates only to the reduced height, and no scroll bar is available. So I want to capture when the user is again clicking the filter in func(), and then call this

qgrid_widget._handle_qgrid_msg_helper({'field':'Highlight', 'filter_info':{'field':'Highlight','selected':[], 'type':'text', 'excluded':[]}, 'type':'change_filter'})

or

call qgrid.show_grid(df) in func.

HariniMadhi commented 1 year ago

Can somebody answer this? I've noticed the same response with 'text_filter_viewport_changed'