Skip to content

Commit b377885

Browse files
author
Tim Shawver
committed
Fix for issue where lots of subsequent scroll events would result in a backlog of events that had to be processed, causing scrolling to appear to be really slow. This was especially apparent in hosted environments like Q where latency is more of an issue.
1 parent 870534a commit b377885

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

js/src/qgrid.widget.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ class QgridView extends widgets.DOMWidgetView {
216216
this.sort_indicator = null;
217217
this.resizing_column = false;
218218
this.ignore_selection_changed = false;
219+
this.vp_response_expected = false;
220+
this.next_viewport_msg = null;
219221

220222
var number_type_info = {
221223
filter: slider_filter.SliderFilter,
@@ -374,7 +376,6 @@ class QgridView extends widgets.DOMWidgetView {
374376
slick_column.editor = null;
375377
}
376378

377-
378379
this.columns.push(slick_column);
379380
}
380381

@@ -498,14 +499,23 @@ class QgridView extends widgets.DOMWidgetView {
498499
}
499500
this.viewport_timeout = setTimeout(() => {
500501
this.last_vp = this.slick_grid.getViewport();
501-
var msg = {
502-
'type': 'change_viewport',
503-
'top': this.last_vp.top,
504-
'bottom': this.last_vp.bottom
505-
};
506-
this.send(msg);
502+
var cur_range = this.model.get('_viewport_range');
503+
504+
if (this.last_vp.top != cur_range[0] || this.last_vp.bottom != cur_range[1]) {
505+
var msg = {
506+
'type': 'change_viewport',
507+
'top': this.last_vp.top,
508+
'bottom': this.last_vp.bottom
509+
};
510+
if (this.vp_response_expected){
511+
this.next_viewport_msg = msg
512+
} else {
513+
this.vp_response_expected = true;
514+
this.send(msg);
515+
}
516+
}
507517
this.viewport_timeout = null;
508-
}, 10);
518+
}, 100);
509519
});
510520

511521
// set up callbacks
@@ -681,6 +691,16 @@ class QgridView extends widgets.DOMWidgetView {
681691
this.multi_index = this.model.get("_multi_index");
682692
var data_view = this.create_data_view(df_json.data);
683693

694+
if (msg.triggered_by === 'change_viewport'){
695+
if (this.next_viewport_msg) {
696+
this.send(this.next_viewport_msg);
697+
this.next_viewport_msg = null;
698+
return;
699+
} else {
700+
this.vp_response_expected = false;
701+
}
702+
}
703+
684704
if (msg.triggered_by == 'change_sort' && this.sort_indicator){
685705
var asc = this.model.get('_sort_ascending');
686706
this.sort_indicator.removeClass(

qgrid/grid.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,10 @@ class QgridWidget(widgets.DOMWidget):
586586
_multi_index = Bool(False, sync=True)
587587
_edited = Bool(False)
588588
_selected_rows = List([])
589-
_viewport_range = Tuple(Integer(), Integer(), default_value=(0, 100))
589+
_viewport_range = Tuple(Integer(),
590+
Integer(),
591+
default_value=(0, 100),
592+
sync=True)
590593
_df_range = Tuple(Integer(), Integer(), default_value=(0, 100), sync=True)
591594
_row_count = Integer(0, sync=True)
592595
_sort_field = Any(None, sync=True)

0 commit comments

Comments
 (0)