Skip to content

Commit 4a8940a

Browse files
author
Tim Shawver
committed
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.
1 parent 5e5339d commit 4a8940a

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

js/src/qgrid.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@
155155
height: 315px !important;
156156
}
157157

158+
.q-grid-toolbar {
159+
display: none;
160+
}
161+
162+
.show-toolbar .q-grid-toolbar {
163+
display: block;
164+
}
165+
158166
.output_scroll .show-toolbar .q-grid {
159167
height: 284px !important;
160168
}

js/src/qgrid.widget.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,21 @@ class QgridView extends widgets.DOMWidgetView {
6262
if (!this.$el.hasClass('q-grid-container')){
6363
this.$el.addClass('q-grid-container');
6464
}
65-
66-
if (this.model.get('show_toolbar')) {
67-
this.initialize_toolbar();
68-
}
69-
65+
this.initialize_toolbar();
7066
this.initialize_slick_grid();
7167
}
7268

7369
initialize_toolbar() {
74-
this.$el.addClass('show-toolbar');
70+
if (!this.model.get('show_toolbar')){
71+
this.$el.removeClass('show-toolbar');
72+
} else {
73+
this.$el.addClass('show-toolbar');
74+
}
75+
76+
if (this.toolbar){
77+
return;
78+
}
79+
7580
this.toolbar = $("<div class='q-grid-toolbar'>").appendTo(this.$el);
7681

7782
let append_btn = (btn_info) => {
@@ -196,7 +201,10 @@ class QgridView extends widgets.DOMWidgetView {
196201
* type of data in the columns of the DataFrame provided by the user.
197202
*/
198203
initialize_slick_grid() {
199-
this.grid_elem = $("<div class='q-grid'>").appendTo(this.$el);
204+
205+
if (!this.grid_elem) {
206+
this.grid_elem = $("<div class='q-grid'>").appendTo(this.$el);
207+
}
200208

201209
// create the table
202210
var df_json = JSON.parse(this.model.get('_df_json'));
@@ -414,6 +422,8 @@ class QgridView extends widgets.DOMWidgetView {
414422
this.slick_grid.setSelectionModel(new Slick.RowSelectionModel());
415423
this.slick_grid.setCellCssStyles("grouping", this.row_styles);
416424
this.slick_grid.render();
425+
426+
this.update_size();
417427

418428
var render_header_cell = (e, args) => {
419429
var cur_filter = this.filters[args.column.id];
@@ -664,7 +674,7 @@ class QgridView extends widgets.DOMWidgetView {
664674
*/
665675
handle_msg(msg) {
666676
if (msg.type === 'draw_table') {
667-
this.initialize_qgrid();
677+
this.initialize_slick_grid();
668678
} else if (msg.type == 'show_error') {
669679
alert(msg.error_msg);
670680
if (msg.triggered_by == 'add_row' ||
@@ -773,6 +783,8 @@ class QgridView extends widgets.DOMWidgetView {
773783
this.slick_grid.scrollRowIntoView(msg.rows[0]);
774784
}
775785
this.ignore_selection_changed = false;
786+
} else if (msg.type == 'change_show_toolbar') {
787+
this.initialize_toolbar();
776788
} else if (msg.col_info) {
777789
var filter = this.filters[msg.col_info.name];
778790
filter.handle_msg(msg);

qgrid/grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ def _grid_options_changed(self):
843843
def _show_toolbar_changed(self):
844844
if not self._initialized:
845845
return
846-
self._rebuild_widget()
846+
self.send({'type': 'change_show_toolbar'})
847847

848848
def _update_table(self,
849849
update_columns=False,

0 commit comments

Comments
 (0)