Skip to content

Commit 9005d45

Browse files
author
Tim Shawver
committed
Adds new 'toggle_editable' and 'change_grid_option' methods, instead of sending a 'toggle_editable' message directly to js.
1 parent ba639cd commit 9005d45

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

js/src/qgrid.widget.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,13 @@ class QgridView extends widgets.DOMWidgetView {
760760
'type': 'change_selection'
761761
});
762762
}, 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-
}
763+
} else if (msg.type == 'change_grid_option') {
764+
var opt_name = msg.option_name;
765+
var opt_val = msg.option_value;
766+
if (this.slick_grid.getOptions()[opt_name] != opt_val) {
767+
this.slick_grid.setOptions({[opt_name]: opt_val});
768+
this.slick_grid.resizeCanvas();
769+
}
769770
} else if (msg.type == 'change_selection') {
770771
this.ignore_selection_changed = true;
771772
this.slick_grid.setSelectedRows(msg.rows);

qgrid/grid.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,5 +1796,32 @@ 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.
1810+
1811+
Parameters
1812+
----------
1813+
option_name : str
1814+
The name of the grid option to be changed.
1815+
option_value : str
1816+
The new value for the grid option.
1817+
"""
1818+
self.grid_options[option_name] = option_value
1819+
self.send({
1820+
'type': 'change_grid_option',
1821+
'option_name': option_name,
1822+
'option_value': option_value
1823+
})
1824+
1825+
17991826
# Alias for legacy support, since we changed the capitalization
18001827
QGridWidget = QgridWidget

0 commit comments

Comments
 (0)