Skip to content

Add 'toggle_editable' method, and fix the 'boldIndex' grid option #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qgrid",
"version": "1.1.0-beta.0",
"version": "1.1.0-beta.1",
"description": "An Interactive Grid for Sorting and Filtering DataFrames in Jupyter Notebook",
"author": "Quantopian Inc.",
"main": "src/index.js",
Expand Down
44 changes: 22 additions & 22 deletions js/src/qgrid.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class QgridModel extends widgets.DOMWidgetModel {
_view_name : 'QgridView',
_model_module : 'qgrid',
_view_module : 'qgrid',
_model_module_version : '^1.1.0-beta.0',
_view_module_version : '^1.1.0-beta.0',
_model_module_version : '^1.1.0-beta.1',
_view_module_version : '^1.1.0-beta.1',
_df_json: '',
_columns: {}
});
Expand Down Expand Up @@ -352,8 +352,7 @@ class QgridView extends widgets.DOMWidgetView {
// don't allow editing index columns
if (cur_column.is_index) {
slick_column.editor = editors.IndexEditor;

slick_column.cssClass += ' idx-col';

if (cur_column.first_index){
slick_column.cssClass += ' first-idx-col';
}
Expand Down Expand Up @@ -682,7 +681,7 @@ class QgridView extends widgets.DOMWidgetView {
this.buttons.tooltip('disable');
}
}
if (this.update_timeout){
if (this.update_timeout) {
clearTimeout(this.update_timeout);
}
this.update_timeout = setTimeout(() => {
Expand All @@ -691,7 +690,7 @@ class QgridView extends widgets.DOMWidgetView {
this.multi_index = this.model.get("_multi_index");
var data_view = this.create_data_view(df_json.data);

if (msg.triggered_by === 'change_viewport'){
if (msg.triggered_by === 'change_viewport') {
if (this.next_viewport_msg) {
this.send(this.next_viewport_msg);
this.next_viewport_msg = null;
Expand All @@ -701,7 +700,7 @@ class QgridView extends widgets.DOMWidgetView {
}
}

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

let top_row = null;
if (msg.triggered_by === 'remove_row'){
if (msg.triggered_by === 'remove_row') {
top_row = this.slick_grid.getViewport().top;
}

this.set_data_view(data_view);

var skip_grouping = false;
if (this.multi_index) {
for (var i=1; i < this.filter_list.length; i++) {
for (var i = 1; i < this.filter_list.length; i++) {
var cur_filter = this.filter_list[i];
if (cur_filter.is_active()) {
skip_grouping = true;
Expand All @@ -737,7 +736,7 @@ class QgridView extends widgets.DOMWidgetView {
this.slick_grid.render();

if ((msg.triggered_by == 'add_row' ||
msg.triggered_by == 'remove_row') && !this.has_active_filter()) {
msg.triggered_by == 'remove_row') && !this.has_active_filter()) {
this.update_size();
}
this.update_timeout = null;
Expand All @@ -760,19 +759,20 @@ class QgridView extends widgets.DOMWidgetView {
'type': 'change_selection'
});
}, 100);
} else if (msg.type == 'toggle_editable') {
if (this.slick_grid.getOptions().editable == false) {
this.slick_grid.setOptions({'editable': true});
} else {
this.slick_grid.setOptions({'editable': false});
}
} else if (msg.type == 'change_grid_option') {
var opt_name = msg.option_name;
var opt_val = msg.option_value;
if (this.slick_grid.getOptions()[opt_name] != opt_val) {
this.slick_grid.setOptions({[opt_name]: opt_val});
this.slick_grid.resizeCanvas();
}
} else if (msg.type == 'change_selection') {
this.ignore_selection_changed = true;
this.slick_grid.setSelectedRows(msg.rows);
if (msg.rows && msg.rows.length > 0) {
this.slick_grid.scrollRowIntoView(msg.rows[0]);
}
this.ignore_selection_changed = false;
this.ignore_selection_changed = true;
this.slick_grid.setSelectedRows(msg.rows);
if (msg.rows && msg.rows.length > 0) {
this.slick_grid.scrollRowIntoView(msg.rows[0]);
}
this.ignore_selection_changed = false;
} else if (msg.col_info) {
var filter = this.filters[msg.col_info.name];
filter.handle_msg(msg);
Expand Down
2 changes: 1 addition & 1 deletion qgrid/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version_info = (1, 1, 0, 'beta', 0)
version_info = (1, 1, 0, 'beta', 1)

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

Expand Down
32 changes: 30 additions & 2 deletions qgrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ class can be constructed directly but that's not recommended because
_model_name = Unicode('QgridModel').tag(sync=True)
_view_module = Unicode('qgrid').tag(sync=True)
_model_module = Unicode('qgrid').tag(sync=True)
_view_module_version = Unicode('1.1.0-beta.0').tag(sync=True)
_model_module_version = Unicode('1.1.0-beta.0').tag(sync=True)
_view_module_version = Unicode('1.1.0-beta.1').tag(sync=True)
_model_module_version = Unicode('1.1.0-beta.1').tag(sync=True)

_df = Instance(pd.DataFrame)
_df_json = Unicode('', sync=True)
Expand Down Expand Up @@ -1796,5 +1796,33 @@ def _change_selection(self, rows, source, send_msg_to_js=False):
'source': source
})

def toggle_editable(self):
"""
Change whether the grid is editable or not, without rebuilding
the entire grid widget.
"""
self.change_grid_option('editable', not self.grid_options['editable'])

def change_grid_option(self, option_name, option_value):
"""
Change a SlickGrid grid option without rebuilding the entire grid
widget. Not all options are supported at this point so this
method should be considered experimental.

Parameters
----------
option_name : str
The name of the grid option to be changed.
option_value : str
The new value for the grid option.
"""
self.grid_options[option_name] = option_value
self.send({
'type': 'change_grid_option',
'option_name': option_name,
'option_value': option_value
})


# Alias for legacy support, since we changed the capitalization
QGridWidget = QgridWidget