Skip to content

Commit 563e7b3

Browse files
author
Tim Shawver
authored
Updating the README for 1.0.3
1 parent 3e5f31d commit 563e7b3

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

README.rst

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ Qgrid is a Jupyter notebook widget which uses `SlickGrid <https://github.com/mle
1111
DataFrames within a Jupyter notebook. This allows you to explore your DataFrames with intuitive scrolling, sorting, and
1212
filtering controls, as well as edit your DataFrames by double clicking cells.
1313

14-
We originally developed qgrid for use in `Quantopian's hosted research environment
15-
<https://www.quantopian.com/research?utm_source=github&utm_medium=web&utm_campaign=qgrid-repo>`_ in fall of 2014, but
16-
had to put it on the backburner for a while so we could focus on higher priority projects.
14+
What's New in 1.0.3 - Introducing Qgrid Events
15+
----------------------------------------------
16+
Qgrid has some new API methods as of version 1.0.3 which can be used to attach event handlers. Event handlers are callback methods that get called when certain events occur in the qgrid interface. In qgrid 1.0.3, event handlers can be attached with the ``on`` method and detached with the ``off`` method. There are ``on`` and ``off`` methods on both the ``qgrid`` module (see `qgrid.on <https://qgrid.readthedocs.io/en/latest/#qgrid.on>`_), and on individual QgridWidget instances (see `qgrid.QgridWidget.on <https://qgrid.readthedocs.io/en/latest/#qgrid.QgridWidget.on>`_).
1717

18-
Qgrid development started up again in summer 2017, when we started a major refactoring project to allow qgrid to take
19-
advantage of the latest advances in ipywidgets (specifically, ipywidget 7.x). As a part of this refactoring we also
20-
moved qgrid's sorting, and filtering logic from the client (javascript) to the server (python). This new version is
21-
called qgrid 1.0, and the instructions that follow are for this new version.
18+
To get a better idea of how these methods might be used, see the `Events API`_ section below.
2219

2320
Demo
2421
----
@@ -199,11 +196,31 @@ read-the-docs page, you can preview your changes locally before submitting a PR
199196
This will result in the ``docs/_build/html`` folder being populated with a new version of the read-the-docs site. If
200197
you open the ``index.html`` file in your browser, you should be able to preview your changes.
201198

202-
Experimental Demo
203-
-----------------
204-
As of qgrid 1.0 there are some interesting ways we can use qgrid in conjunction with other widgets/visualizations. One example is using qgrid to filter a DataFrame that's also being displayed by another visualization.
199+
Events API
200+
----------
201+
As of qgrid 1.0.3 there are new ``on`` and ``off`` methods in qgrid which can be used to attach/detach event handlers. Previously the only way to listen for events was to use undocumented parts of the API.
202+
203+
Having the ability to attach event handlers allows us to do some interesting things in terms of using qgrid in conjunction with other widgets/visualizations. One example is using qgrid to filter a DataFrame that's also being displayed by another visualization.
204+
205+
If you previously used the ``observe`` method to respond to qgrid events, lets see how your code might be updated to use the new ``on`` method::
206+
207+
# Before upgrading to 1.0.3
208+
def handle_df_change(change):
209+
print(change['new'])
210+
211+
qgrid_widget.observe(handle_df_change, names=['_df'])
212+
213+
When you upgrade to 1.0.3, you have more granular control over which events you do an don't listen to, but you can also replicate the previous behavior of calling ``print`` every time the state of the internal DataFrame is changed. Here's what that would look like using the new ``on`` method::
214+
215+
# After upgrading to 1.0.3
216+
def handle_json_updated(event, qgrid_widget):
217+
# exclude 'viewport_changed' events since that doesn't change the DataFrame
218+
if (event['triggered_by'] != 'viewport_changed'):
219+
print(qgrid_widget.get_changed_df())
220+
221+
qgrid_widget.on('json_updated', handle_json_updated)
205222

206-
Currently these ways of using qgrid are not documented in the API docs or extensively tested, so they're still considered experimental. See the `experimental notebook <https://beta.mybinder.org/v2/gh/quantopian/qgrid-notebooks/master?filepath=experimental.ipynb>`_ to learn more.
223+
See the `events notebook <https://mybinder.org/v2/gh/quantopian/qgrid-notebooks/master?filepath=index.ipynb>`_ for more examples of using these new API methods.
207224

208225
For people who would rather not go to another page to try out the experimental notebook, here's the tldr; version:
209226

0 commit comments

Comments
 (0)