From 4a8940ab7e79015c406784a4b8fcbf8e0f7e64c9 Mon Sep 17 00:00:00 2001 From: Tim Shawver Date: Wed, 11 Jul 2018 00:56:05 -0400 Subject: [PATCH 1/4] Fixing issue where the grid widget would noticeably flash when the dataframe was swapped out via the df property. This should make the transition more smooth and address #186. --- js/src/qgrid.css | 8 ++++++++ js/src/qgrid.widget.js | 28 ++++++++++++++++++++-------- qgrid/grid.py | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/js/src/qgrid.css b/js/src/qgrid.css index 80ebb0c7..a0553074 100644 --- a/js/src/qgrid.css +++ b/js/src/qgrid.css @@ -155,6 +155,14 @@ height: 315px !important; } +.q-grid-toolbar { + display: none; +} + +.show-toolbar .q-grid-toolbar { + display: block; +} + .output_scroll .show-toolbar .q-grid { height: 284px !important; } diff --git a/js/src/qgrid.widget.js b/js/src/qgrid.widget.js index a39fade8..194d017d 100644 --- a/js/src/qgrid.widget.js +++ b/js/src/qgrid.widget.js @@ -62,16 +62,21 @@ class QgridView extends widgets.DOMWidgetView { if (!this.$el.hasClass('q-grid-container')){ this.$el.addClass('q-grid-container'); } - - if (this.model.get('show_toolbar')) { - this.initialize_toolbar(); - } - + this.initialize_toolbar(); this.initialize_slick_grid(); } initialize_toolbar() { - this.$el.addClass('show-toolbar'); + if (!this.model.get('show_toolbar')){ + this.$el.removeClass('show-toolbar'); + } else { + this.$el.addClass('show-toolbar'); + } + + if (this.toolbar){ + return; + } + this.toolbar = $("
").appendTo(this.$el); let append_btn = (btn_info) => { @@ -196,7 +201,10 @@ class QgridView extends widgets.DOMWidgetView { * type of data in the columns of the DataFrame provided by the user. */ initialize_slick_grid() { - this.grid_elem = $("
").appendTo(this.$el); + + if (!this.grid_elem) { + this.grid_elem = $("
").appendTo(this.$el); + } // create the table var df_json = JSON.parse(this.model.get('_df_json')); @@ -414,6 +422,8 @@ class QgridView extends widgets.DOMWidgetView { this.slick_grid.setSelectionModel(new Slick.RowSelectionModel()); this.slick_grid.setCellCssStyles("grouping", this.row_styles); this.slick_grid.render(); + + this.update_size(); var render_header_cell = (e, args) => { var cur_filter = this.filters[args.column.id]; @@ -664,7 +674,7 @@ class QgridView extends widgets.DOMWidgetView { */ handle_msg(msg) { if (msg.type === 'draw_table') { - this.initialize_qgrid(); + this.initialize_slick_grid(); } else if (msg.type == 'show_error') { alert(msg.error_msg); if (msg.triggered_by == 'add_row' || @@ -773,6 +783,8 @@ class QgridView extends widgets.DOMWidgetView { this.slick_grid.scrollRowIntoView(msg.rows[0]); } this.ignore_selection_changed = false; + } else if (msg.type == 'change_show_toolbar') { + this.initialize_toolbar(); } else if (msg.col_info) { var filter = this.filters[msg.col_info.name]; filter.handle_msg(msg); diff --git a/qgrid/grid.py b/qgrid/grid.py index 46eab86b..d2ba102a 100644 --- a/qgrid/grid.py +++ b/qgrid/grid.py @@ -843,7 +843,7 @@ def _grid_options_changed(self): def _show_toolbar_changed(self): if not self._initialized: return - self._rebuild_widget() + self.send({'type': 'change_show_toolbar'}) def _update_table(self, update_columns=False, From bb59113b5bc2d10950209e2df67c3ffc8c6ab495 Mon Sep 17 00:00:00 2001 From: Tim Shawver Date: Wed, 11 Jul 2018 00:57:04 -0400 Subject: [PATCH 2/4] Add a doc string for the edit cell method, which was missing. --- qgrid/grid.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/qgrid/grid.py b/qgrid/grid.py index d2ba102a..dcd10e73 100644 --- a/qgrid/grid.py +++ b/qgrid/grid.py @@ -1689,6 +1689,20 @@ def _add_row(self, row): return index_col_val def edit_cell(self, index, column, value): + """ + Edit a cell of the grid, given the index and column of the cell + to edit, as well as the new value of the cell. Results in a + ``cell_edited`` event being fired. + + Parameters + ---------- + index : object + The index of the row containing the cell that is to be edited. + column : str + The name of the column containing the cell that is to be edited. + value : object + The new value for the cell. + """ old_value = self._df.loc[index, column] self._df.loc[index, column] = value self._unfiltered_df.loc[index, column] = value From a37c2012e48ad6f5d43afffe74d761ef645964e1 Mon Sep 17 00:00:00 2001 From: Tim Shawver Date: Wed, 11 Jul 2018 01:20:04 -0400 Subject: [PATCH 3/4] Store a reference to the SlickGrid object on the grid element via jquery. This is convenient for debugging and integrating with other js components. --- js/src/qgrid.widget.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/src/qgrid.widget.js b/js/src/qgrid.widget.js index 194d017d..52274f6b 100644 --- a/js/src/qgrid.widget.js +++ b/js/src/qgrid.widget.js @@ -399,6 +399,7 @@ class QgridView extends widgets.DOMWidgetView { this.columns, this.grid_options ); + this.grid_elem.data('slickgrid', this.slick_grid); if (this.grid_options.forceFitColumns){ this.grid_elem.addClass('force-fit-columns'); From 050fc01a51278809b6d2d24d913f5a30bd0a0f31 Mon Sep 17 00:00:00 2001 From: Tim Shawver Date: Wed, 11 Jul 2018 01:57:31 -0400 Subject: [PATCH 4/4] Bump to 1.1.1 --- js/package.json | 2 +- js/src/qgrid.widget.js | 4 ++-- qgrid/_version.py | 2 +- qgrid/grid.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/js/package.json b/js/package.json index e705f8a0..17ef05d3 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "qgrid", - "version": "1.1.0", + "version": "1.1.1", "description": "An Interactive Grid for Sorting and Filtering DataFrames in Jupyter Notebook", "author": "Quantopian Inc.", "main": "src/index.js", diff --git a/js/src/qgrid.widget.js b/js/src/qgrid.widget.js index 52274f6b..9cfe94df 100644 --- a/js/src/qgrid.widget.js +++ b/js/src/qgrid.widget.js @@ -36,8 +36,8 @@ class QgridModel extends widgets.DOMWidgetModel { _view_name : 'QgridView', _model_module : 'qgrid', _view_module : 'qgrid', - _model_module_version : '^1.1.0', - _view_module_version : '^1.1.0', + _model_module_version : '^1.1.1', + _view_module_version : '^1.1.1', _df_json: '', _columns: {} }); diff --git a/qgrid/_version.py b/qgrid/_version.py index 50096604..54554498 100644 --- a/qgrid/_version.py +++ b/qgrid/_version.py @@ -1,4 +1,4 @@ -version_info = (1, 1, 0, 'final') +version_info = (1, 1, 1, 'final') _specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''} diff --git a/qgrid/grid.py b/qgrid/grid.py index dcd10e73..b0e76dde 100644 --- a/qgrid/grid.py +++ b/qgrid/grid.py @@ -566,8 +566,8 @@ class can be constructed directly but that's not recommended because _model_name = Unicode('QgridModel').tag(sync=True) _view_module = Unicode('qgrid').tag(sync=True) _model_module = Unicode('qgrid').tag(sync=True) - _view_module_version = Unicode('1.1.0').tag(sync=True) - _model_module_version = Unicode('1.1.0').tag(sync=True) + _view_module_version = Unicode('1.1.1').tag(sync=True) + _model_module_version = Unicode('1.1.1').tag(sync=True) _df = Instance(pd.DataFrame) _df_json = Unicode('', sync=True)