Skip to content

Commit 6cb3d89

Browse files
authored
Merge pull request #210 from quantopian/fix-bold-index
Add 'toggle_editable' method, and fix the 'boldIndex' grid option
2 parents ba639cd + 71e7ed3 commit 6cb3d89

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
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.1.0-beta.0",
3+
"version": "1.1.0-beta.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/qgrid.widget.js

Lines changed: 22 additions & 22 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.1.0-beta.0',
40-
_view_module_version : '^1.1.0-beta.0',
39+
_model_module_version : '^1.1.0-beta.1',
40+
_view_module_version : '^1.1.0-beta.1',
4141
_df_json: '',
4242
_columns: {}
4343
});
@@ -352,8 +352,7 @@ class QgridView extends widgets.DOMWidgetView {
352352
// don't allow editing index columns
353353
if (cur_column.is_index) {
354354
slick_column.editor = editors.IndexEditor;
355-
356-
slick_column.cssClass += ' idx-col';
355+
357356
if (cur_column.first_index){
358357
slick_column.cssClass += ' first-idx-col';
359358
}
@@ -682,7 +681,7 @@ class QgridView extends widgets.DOMWidgetView {
682681
this.buttons.tooltip('disable');
683682
}
684683
}
685-
if (this.update_timeout){
684+
if (this.update_timeout) {
686685
clearTimeout(this.update_timeout);
687686
}
688687
this.update_timeout = setTimeout(() => {
@@ -691,7 +690,7 @@ class QgridView extends widgets.DOMWidgetView {
691690
this.multi_index = this.model.get("_multi_index");
692691
var data_view = this.create_data_view(df_json.data);
693692

694-
if (msg.triggered_by === 'change_viewport'){
693+
if (msg.triggered_by === 'change_viewport') {
695694
if (this.next_viewport_msg) {
696695
this.send(this.next_viewport_msg);
697696
this.next_viewport_msg = null;
@@ -701,7 +700,7 @@ class QgridView extends widgets.DOMWidgetView {
701700
}
702701
}
703702

704-
if (msg.triggered_by == 'change_sort' && this.sort_indicator){
703+
if (msg.triggered_by == 'change_sort' && this.sort_indicator) {
705704
var asc = this.model.get('_sort_ascending');
706705
this.sort_indicator.removeClass(
707706
'fa-spinner fa-spin fa-sort-asc fa-sort-desc'
@@ -712,15 +711,15 @@ class QgridView extends widgets.DOMWidgetView {
712711
}
713712

714713
let top_row = null;
715-
if (msg.triggered_by === 'remove_row'){
714+
if (msg.triggered_by === 'remove_row') {
716715
top_row = this.slick_grid.getViewport().top;
717716
}
718717

719718
this.set_data_view(data_view);
720719

721720
var skip_grouping = false;
722721
if (this.multi_index) {
723-
for (var i=1; i < this.filter_list.length; i++) {
722+
for (var i = 1; i < this.filter_list.length; i++) {
724723
var cur_filter = this.filter_list[i];
725724
if (cur_filter.is_active()) {
726725
skip_grouping = true;
@@ -737,7 +736,7 @@ class QgridView extends widgets.DOMWidgetView {
737736
this.slick_grid.render();
738737

739738
if ((msg.triggered_by == 'add_row' ||
740-
msg.triggered_by == 'remove_row') && !this.has_active_filter()) {
739+
msg.triggered_by == 'remove_row') && !this.has_active_filter()) {
741740
this.update_size();
742741
}
743742
this.update_timeout = null;
@@ -760,19 +759,20 @@ class QgridView extends widgets.DOMWidgetView {
760759
'type': 'change_selection'
761760
});
762761
}, 100);
763-
} else if (msg.type == 'toggle_editable') {
764-
if (this.slick_grid.getOptions().editable == false) {
765-
this.slick_grid.setOptions({'editable': true});
766-
} else {
767-
this.slick_grid.setOptions({'editable': false});
768-
}
762+
} else if (msg.type == 'change_grid_option') {
763+
var opt_name = msg.option_name;
764+
var opt_val = msg.option_value;
765+
if (this.slick_grid.getOptions()[opt_name] != opt_val) {
766+
this.slick_grid.setOptions({[opt_name]: opt_val});
767+
this.slick_grid.resizeCanvas();
768+
}
769769
} else if (msg.type == 'change_selection') {
770-
this.ignore_selection_changed = true;
771-
this.slick_grid.setSelectedRows(msg.rows);
772-
if (msg.rows && msg.rows.length > 0) {
773-
this.slick_grid.scrollRowIntoView(msg.rows[0]);
774-
}
775-
this.ignore_selection_changed = false;
770+
this.ignore_selection_changed = true;
771+
this.slick_grid.setSelectedRows(msg.rows);
772+
if (msg.rows && msg.rows.length > 0) {
773+
this.slick_grid.scrollRowIntoView(msg.rows[0]);
774+
}
775+
this.ignore_selection_changed = false;
776776
} else if (msg.col_info) {
777777
var filter = this.filters[msg.col_info.name];
778778
filter.handle_msg(msg);

qgrid/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version_info = (1, 1, 0, 'beta', 0)
1+
version_info = (1, 1, 0, 'beta', 1)
22

33
_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}
44

qgrid/grid.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,8 @@ class can be constructed directly but that's not recommended because
566566
_model_name = Unicode('QgridModel').tag(sync=True)
567567
_view_module = Unicode('qgrid').tag(sync=True)
568568
_model_module = Unicode('qgrid').tag(sync=True)
569-
_view_module_version = Unicode('1.1.0-beta.0').tag(sync=True)
570-
_model_module_version = Unicode('1.1.0-beta.0').tag(sync=True)
569+
_view_module_version = Unicode('1.1.0-beta.1').tag(sync=True)
570+
_model_module_version = Unicode('1.1.0-beta.1').tag(sync=True)
571571

572572
_df = Instance(pd.DataFrame)
573573
_df_json = Unicode('', sync=True)
@@ -1796,5 +1796,33 @@ def _change_selection(self, rows, source, send_msg_to_js=False):
17961796
'source': source
17971797
})
17981798

1799+
def toggle_editable(self):
1800+
"""
1801+
Change whether the grid is editable or not, without rebuilding
1802+
the entire grid widget.
1803+
"""
1804+
self.change_grid_option('editable', not self.grid_options['editable'])
1805+
1806+
def change_grid_option(self, option_name, option_value):
1807+
"""
1808+
Change a SlickGrid grid option without rebuilding the entire grid
1809+
widget. Not all options are supported at this point so this
1810+
method should be considered experimental.
1811+
1812+
Parameters
1813+
----------
1814+
option_name : str
1815+
The name of the grid option to be changed.
1816+
option_value : str
1817+
The new value for the grid option.
1818+
"""
1819+
self.grid_options[option_name] = option_value
1820+
self.send({
1821+
'type': 'change_grid_option',
1822+
'option_name': option_name,
1823+
'option_value': option_value
1824+
})
1825+
1826+
17991827
# Alias for legacy support, since we changed the capitalization
18001828
QGridWidget = QgridWidget

0 commit comments

Comments
 (0)