Skip to content

filtered traitlet #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion qgrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from IPython.html import widgets
from IPython.display import display, Javascript
try:
from traitlets import Unicode, Instance, Bool, Integer, Dict, List
from traitlets import Unicode, Instance, Bool, Integer, Dict, List, observe
except ImportError:
from IPython.utils.traitlets import (
Unicode, Instance, Bool, Integer, Dict, List
Expand Down Expand Up @@ -233,6 +233,7 @@ class QGridWidget(widgets.DOMWidget):
_multi_index = Bool(False)
_selected_rows = List()

filtered = List(sync=True)
df = Instance(pd.DataFrame)
precision = Integer(6)
grid_options = Dict(sync=True)
Expand Down Expand Up @@ -271,6 +272,8 @@ def _update_table(self):
if not df.index.name:
df.index.name = 'Index'

self.filtered = df.index.tolist()

if type(df.index) == pd.core.index.MultiIndex:
df.reset_index(inplace=True)
self._multi_index = True
Expand Down Expand Up @@ -385,3 +388,10 @@ def export(self, value=None):

display_html(raw_html, raw=True)
display_javascript(raw_js, raw=True)

@observe('filtered')
def filtered_changed(self, change):
self.filtered = [ ]
for index in change['new']:
self.filtered.append(int(index))

12 changes: 12 additions & 0 deletions qgrid/qgridjs/qgrid.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ define([path], function(widget) {
grid = new this.dgrid.QGrid(this.tableDiv, df, column_types);
grid.initialize_slick_grid(options);

grid.data_view.onRowCountChanged.subscribe(function(e, args) {
var items = grid.data_view.getItems();
var indexes = [ ];
for (var i in items) {
if (items[i].include) {
indexes.push(items[i].Index);
}
}
that.model.set('filtered', indexes);
that.model.save_changes();
});

// set up editing
var sgrid = grid.slick_grid;
var columns = sgrid.getColumns();
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
notebook>=4.0.0
pandas>=0.16.2
ipywidgets>=4.0.0
jupyter-pip>=0.3.0
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
join, dirname, abspath
)

#jchuahtacc
try:
from jupyterpip import cmdclass
except:
import pip, importlib
pip.main(['install', 'jupyter-pip']); cmdclass = importlib.import_module('jupyterpip').cmdclass

def read_requirements(basename):
reqs_file = join(dirname(abspath(__file__)), basename)
Expand Down Expand Up @@ -50,5 +56,6 @@ def read_requirements(basename):
'Topic :: Scientific/Engineering :: Information Analysis',
],
install_requires=reqs,
url="https://github.com/quantopian/qgrid"
url="https://github.com/quantopian/qgrid",
cmdclass=cmdclass('qgrid/qgridjs'),
)