Open frankghe opened 4 years ago
You forgot the global statement before modifying a local variable
count=0
def record_change(event, widget):
global count
count +=1
print('handler fired')
grid.on(names='cell_edited',handler=record_change)
grid
Avoid global like the plague:
class QgridCounter():
def record_change(self, event, grid_widget):
self.count +=1
print('handler fired %d times'%self.count)
def __init__(self):
self.df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
self.grid_widget = qgrid.show_grid(self.df, show_toolbar=True)
self.grid_widget.on(names='cell_edited',handler=self.record_change)
self.count = 0
def disp(self):
display(self.grid_widget)
QgridCounter().disp()
Environment
Operating System: Win 10
Python Version: 3.7.7
How did you install Qgrid: pip
Python packages:
$ pip freeze
or$ conda list
(please include qgrid, notebook, and jupyterlab versions) jupyter-client==6.1.3 jupyter-core==4.6.3 jupyterlab==1.2.6 jupyterlab-server==1.1.4 matplotlib==3.1.3 notebook==6.0.3 pandas==1.0.3 qgrid==1.3.1Jupyter lab packages (if applicable):
$ jupyter labextension list
JupyterLab v1.2.6 Known labextensions: app dir: C:\Users\fghenass\Anaconda3\envs\realestate\share\jupyter\lab @8080labs/qgrid v1.1.1 enabled ok @jupyter-widgets/jupyterlab-manager v1.1.0 enabled ok @jupyterlab/debugger v0.1.2 enabled ok qgrid2 v1.1.3 enabled okUninstalled core extensions: @8080labs/qgrid
Description of Issue
Methods qgrid.on() and QgridWidget.on() have no effect, ie. handler is registered, but never called.
Reproduction Steps
Code below can be used to reproduce problem:
import pandas as pd import qgrid df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}) grid = qgrid.show_grid(df, show_toolbar=True) grid count=0 def record_change(event, widget): count +=1 print('handler fired') grid.on(names='cell_edited',handler=record_change)
Note: other events also do not fire the event, nor
I also tried to use the example provided in the following page, with same result (graph not updated in this case): https://github.com/quantopian/qgrid-notebooks/blob/master/events.ipynb
What steps have you taken to resolve this already?
...
Anything else?
...