Skip to content

Commit 2af90ed

Browse files
authored
Merge pull request #162 from quantopian/page_size
Fix issue where qgrid would prevent all other jupyterlab widgets from working
2 parents 2c9f9ad + 7127b22 commit 2af90ed

File tree

13 files changed

+250
-73
lines changed

13 files changed

+250
-73
lines changed

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qgrid",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "An Interactive Grid for Sorting and Filtering DataFrames in Jupyter Notebook",
55
"author": "Quantopian Inc.",
66
"main": "src/index.js",

js/src/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
// Entry point for the notebook bundle containing custom model definitions.
2-
//
3-
// Setup notebook base URL
4-
//
5-
// Some static assets may be required by the custom widget javascript. The base
6-
// url for the notebook is not known at build time and is therefore computed
7-
// dynamically.
8-
__webpack_public_path__ = document.querySelector('body').getAttribute('data-base-url') + 'nbextensions/qgrid/';
9-
102
// Export widget models and views, and the npm package version number.
113
module.exports = require('./qgrid.widget.js');
124
module.exports.version = require('../package.json').version;

js/src/qgrid.booleanfilter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class BooleanFilter extends filter_base.FilterBase {
7979
reset_filter() {
8080
this.radio_buttons.prop('checked', false);
8181
this.selected = null;
82+
this.send_filter_changed();
8283
}
8384

8485
get_filter_info() {

js/src/qgrid.css

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@
284284
}
285285

286286
.q-grid .slick-cell {
287-
border-bottom: 1px solid #e1e8ed !important;
288-
border-right: none !important;
287+
border-bottom: 1px solid #e1e8ed;
288+
border-right: none;
289289
border-top: 1px solid transparent;
290290
border-left: 1px solid transparent;
291291
font-size: 13px;
@@ -294,6 +294,32 @@
294294
padding-left: 0px;
295295
}
296296

297+
.q-grid.highlight-selected-row .slick-cell.selected {
298+
background-color: #deeaf7;
299+
}
300+
301+
.q-grid.highlight-selected-cell .slick-cell.active {
302+
border: 2px solid rgb(65, 165, 245);
303+
padding-top: 2px;
304+
padding-bottom: 1px;
305+
padding-left: 3px;
306+
}
307+
308+
.q-grid .slick-cell.editable:not(.idx-col) {
309+
border: 2px solid rgb(65, 165, 245);
310+
padding-top: 2px;
311+
padding-bottom: 1px;
312+
padding-left: 3px !important;
313+
background-color: #FFF;
314+
-webkit-box-shadow: 0 2px 5px rgba(0,0,0,0.4);
315+
-moz-box-shadow: 0 2px 5px rgba(0,0,0,0.4);
316+
box-shadow: 0 2px 5px rgba(0,0,0,0.4);
317+
}
318+
319+
.q-grid .slick-cell.editable .editor-select:focus {
320+
outline-style: none;
321+
}
322+
297323
.q-grid .slick-cell.idx-col {
298324
font-weight: bold;
299325
}
@@ -304,7 +330,7 @@
304330
}
305331

306332
.q-grid .slick-cell.selected {
307-
background-color: #deeaf7;
333+
background-color: transparent;
308334
}
309335

310336
/* Filter button */
@@ -605,18 +631,6 @@ input.bool-filter-radio {
605631
margin-left: -23px;
606632
}
607633

608-
.slick-cell.editable:not(.idx-col) {
609-
background-color: rgb(255, 247, 141) !important;
610-
border: 1px solid rgba(0, 0, 0, 0.26) !important;
611-
margin-top: -1px;
612-
padding-top: 4px;
613-
padding-bottom: 2px;
614-
}
615-
616-
.slick-cell.editable:not(:last-child):not(.idx-col) {
617-
margin-right: 3px;
618-
}
619-
620634
.slick-cell {
621635
-webkit-touch-callout: none; /* iOS Safari */
622636
-webkit-user-select: none; /* Safari */
@@ -627,6 +641,5 @@ input.bool-filter-radio {
627641
}
628642

629643
.slick-row .slick-cell:not(:first-child) {
630-
margin-left: -4px;
631644
padding-left: 4px;
632645
}

js/src/qgrid.datefilter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class DateFilter extends filter_base.FilterBase {
5151

5252
this.filter_start_date = null;
5353
this.filter_end_date = null;
54+
this.send_filter_changed();
5455
}
5556

5657
initialize_controls() {

js/src/qgrid.editors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class IndexEditor {
1616
this.$cell.tooltip();
1717
this.$cell.tooltip('enable');
1818
this.$cell.tooltip("open");
19-
this.$cell.off('tooltipclose');
20-
this.$cell.on("tooltipclose", (event, ui) => {
19+
// automatically hide it after 4 seconds
20+
setTimeout((event, ui) => {
2121
this.$cell.tooltip('destroy');
2222
args.cancelChanges();
23-
});
23+
}, 3000);
2424
}
2525

2626
destroy() {}

js/src/qgrid.filterbase.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ class FilterBase {
152152

153153
initialize_controls() {
154154
this.filter_elem.find("a.reset-link").click(
155-
(e) => this.handle_reset_filter_clicked(e)
155+
(e) => this.reset_filter()
156156
);
157157
this.filter_elem.find("i.close-button").click(
158-
(e) => this.handle_close_button_clicked(e)
158+
(e) => this.hide_filter()
159159
);
160160
$(document.body).bind("mousedown",
161161
(e) => this.handle_body_mouse_down(e)
@@ -180,22 +180,6 @@ class FilterBase {
180180
this.widget_model.send(msg);
181181
}
182182

183-
handle_reset_filter_clicked(e) {
184-
this.reset_filter();
185-
this.send_filter_changed();
186-
// The "false" parameter tells backtest_table_manager that we want to recalculate the min/max values for this filter
187-
// based on the rows that are still included in the grid. This is because if this filter was already active,
188-
// its min/max could be out-of-date because we don't adjust the min/max on active filters (to prevent confusion).
189-
// This is currently the only filter_changed case where it's appropriate to have this filter's min/max recalculated,
190-
// because you wouldn't want to adjust a slider's min/max while the user was moving the slider, for example.
191-
return false;
192-
}
193-
194-
handle_close_button_clicked(e) {
195-
this.hide_filter();
196-
return false;
197-
}
198-
199183
handle_body_mouse_down(e) {
200184
if (this.filter_elem && this.filter_elem[0] != e.target && !$.contains(this.filter_elem[0], e.target) &&
201185
!$.contains(this.filter_btn[0], e.target) &&

js/src/qgrid.sliderfilter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class SliderFilter extends filter_base.FilterBase {
100100
});
101101
this.set_value(this.min_value, this.max_value);
102102
}
103+
this.send_filter_changed();
103104
}
104105

105106
is_active() {

js/src/qgrid.textfilter.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,20 @@ class TextFilter extends filter_base.FilterBase {
355355
}
356356

357357
reset_filter() {
358+
this.ignore_selection_changed = true;
358359
this.search_string = "";
359360
this.excluded_rows = null;
360361
this.security_search.val("");
361362
this.row_selection_model.setSelectedRows([]);
362363
this.filter_list = null;
364+
this.send_filter_changed();
365+
var msg = {
366+
'type': 'get_column_min_max',
367+
'field': this.field,
368+
'search_val': this.search_string
369+
};
370+
this.widget_model.send(msg);
371+
this.ignore_selection_changed = false;
363372
}
364373

365374
get_filter_info() {

js/src/qgrid.widget.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class QgridModel extends widgets.DOMWidgetModel {
3636
_view_name : 'QgridView',
3737
_model_module : 'qgrid',
3838
_view_module : 'qgrid',
39-
_model_module_version : '^1.0.0',
40-
_view_module_version : '^1.0.0',
39+
_model_module_version : '^1.0.1',
40+
_view_module_version : '^1.0.1',
4141
_df_json: '',
4242
_columns: {}
4343
});
@@ -370,6 +370,16 @@ class QgridView extends widgets.DOMWidgetView {
370370
this.grid_elem.addClass('force-fit-columns');
371371
}
372372

373+
if (this.grid_options.highlightSelectedCell) {
374+
this.grid_elem.addClass('highlight-selected-cell');
375+
}
376+
377+
// compare to false since we still want to show row
378+
// selection if this option is excluded entirely
379+
if (this.grid_options.highlightSelectedRow != false) {
380+
this.grid_elem.addClass('highlight-selected-row');
381+
}
382+
373383
setTimeout(() => {
374384
this.slick_grid.init();
375385
this.update_size();
@@ -378,12 +388,16 @@ class QgridView extends widgets.DOMWidgetView {
378388
this.slick_grid.setSelectionModel(new Slick.RowSelectionModel());
379389
this.slick_grid.render();
380390

381-
this.slick_grid.onHeaderCellRendered.subscribe((e, args) => {
391+
var render_header_cell = (e, args) => {
382392
var cur_filter = this.filters[args.column.id];
383-
if (cur_filter){
384-
cur_filter.render_filter_button($(args.node), this.slick_grid);
385-
}
386-
});
393+
if (cur_filter) {
394+
cur_filter.render_filter_button($(args.node), this.slick_grid);
395+
}
396+
};
397+
398+
if (this.grid_options.filterable != false) {
399+
this.slick_grid.onHeaderCellRendered.subscribe(render_header_cell);
400+
}
387401

388402
// Force the grid to re-render the column headers so the
389403
// onHeaderCellRendered event is triggered.
@@ -396,7 +410,7 @@ class QgridView extends widgets.DOMWidgetView {
396410
this.slick_grid.setSortColumns([]);
397411

398412
this.grid_header = this.$el.find('.slick-header-columns');
399-
this.grid_header.click((e) => {
413+
var handle_header_click = (e) => {
400414
if (this.resizing_column) {
401415
return;
402416
}
@@ -436,7 +450,11 @@ class QgridView extends widgets.DOMWidgetView {
436450
'sort_ascending': this.sort_ascending
437451
};
438452
this.send(msg);
439-
});
453+
};
454+
455+
if (this.grid_options.sortable != false) {
456+
this.grid_header.click(handle_header_click)
457+
}
440458

441459
this.slick_grid.onViewportChanged.subscribe((e) => {
442460
if (this.viewport_timeout){
@@ -491,6 +509,18 @@ class QgridView extends widgets.DOMWidgetView {
491509
}, 1);
492510
}
493511

512+
processPhosphorMessage(msg) {
513+
super.processPhosphorMessage(msg)
514+
switch (msg.type) {
515+
case 'resize':
516+
case 'after-show':
517+
if (this.slick_grid){
518+
this.slick_grid.resizeCanvas();
519+
}
520+
break;
521+
}
522+
}
523+
494524
has_active_filter() {
495525
for (var i=0; i < this.filter_list.length; i++){
496526
var cur_filter = this.filter_list[i];

0 commit comments

Comments
 (0)