<jupyter_start><jupyter_text>install & docs<jupyter_code>pip install qgrid
# solving problems: https://github.com/quantopian/qgrid/issues/253
# jupyter nbextension enable --py --sys-prefix qgrid
# jupyter nbextension enable --py --sys-prefix widgetsnbextension

"""
qgrid method 'on':
    https://qgrid.readthedocs.io/en/v1.1.0/#qgrid.QgridWidget.on
    
events:
[
    'cell_edited',
    'selection_changed',
    'viewport_changed',
    'row_added',
    'row_removed',
    'filter_dropdown_shown',
    'filter_changed',
    'sort_changed',
    'text_filter_viewport_changed',
    'json_updated'
]
"""<jupyter_output><empty_output><jupyter_text>window & df table setup<jupyter_code>import pandas as pd
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('max_colwidth', 100)<jupyter_output><empty_output><jupyter_text>qgrid with 'on' method example<jupyter_code>import qgrid
import pandas as pd
from traitlets import All


def make_action(row, new_state):
    print('[*] some action with row data')
    return None


def handle_column_update(event, qgrid_widget):
    # exclude 'viewport_changed' events since that doesn't change the DataFrame
    if event['column'] == 'thing':
        print(event)
        changed_df = qgrid_widget.get_changed_df()
        row = changed_df.iloc[event['index']]
        new_state = event['new']
        
        make_action(row, new_state)
        # think of making some changes in qgrid programmatically
        # after action was taken e.g. changing cell bg color
        # to signalize to the user
    return None


if __name__ == "__main__":
    # ********* create or read data frame *********
    data_set = [
        ['some', 'thing', 'here'],
        [11, True, 'text'],
        [22, False, 'new'],
        [33, True, 'next'],
        [44, False, 'line'],
        [55, False, 'here'],
        [66, True, 'text'],
    ]
    headers = data_set.pop(0)
    df = pd.DataFrame(data_set, columns=headers)
    
    # ********* make qgrid object with event handler *********
    widget = qgrid.show_grid(df)
    widget.on('cell_edited', handle_column_update)
    
    # ********* display qgrid *********
    display(widget)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14565587734241908, 'fraction_numerical': 0.010647359454855196, 'mean_word_length': 3.6058823529411765, 'pattern_counts': {'":': 1, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '488190', 'license': 'MIT', 'n_tokens_mistral': 807, 'n_tokens_neox': 778, 'n_words': 176, 'path': 'qgrid_on_method/qgrid_on_method.ipynb', 'repo_name': 'streanger/jupyter_notebooks', 'size': '2348'}