diff --git a/js/src/qgrid.widget.js b/js/src/qgrid.widget.js index 9cfe94df..3e8dd1c3 100644 --- a/js/src/qgrid.widget.js +++ b/js/src/qgrid.widget.js @@ -545,6 +545,15 @@ class QgridView extends widgets.DOMWidgetView { 'value': args.item[column], 'type': 'edit_cell'}; this.send(msg); }); + + this.slick_grid.onActiveCellChanged.subscribe((e, args) => { + var column = this.columns[args.cell].name; + var data_item = this.slick_grid.getDataItem(args.row); + var msg = {'row_index': data_item.row_index, 'column': column, + 'unfiltered_index': data_item[this.index_col_name], + 'value': args.item[column], 'type': 'active_cell_changed'}; + this.send(msg); + }); this.slick_grid.onSelectedRowsChanged.subscribe((e, args) => { if (!this.ignore_selection_changed) { diff --git a/qgrid/grid.py b/qgrid/grid.py index b0e76dde..d8529984 100644 --- a/qgrid/grid.py +++ b/qgrid/grid.py @@ -205,6 +205,7 @@ def on(names, handler): [ 'instance_created', 'cell_edited', + 'active_cell_changed', 'selection_changed', 'viewport_changed', 'row_added', @@ -661,6 +662,7 @@ def on(self, names, handler): [ 'cell_edited', + 'active_cell_changed', 'selection_changed', 'viewport_changed', 'row_added', @@ -683,6 +685,11 @@ def on(self, names, handler): * **column** The name of the column that contains the edited cell. * **old** The previous value of the cell. * **new** The new value of the cell. + + * **active_cell_changed** The user changed the active cell in the grid. + * **index** The index of the row that contains the active cell. + * **column** The name of the column that contains the active cell. + * **new** The value of the active cell. * **filter_changed** The user changed the filter setting for a column. @@ -1426,9 +1433,10 @@ def _handle_qgrid_msg_helper(self, content): if 'type' not in content: return - if content['type'] == 'edit_cell': + if content['type'] in ('edit_cell', 'active_cell_changed'): col_info = self._columns[content['column']] try: + event_name = 'cell_edited' if content['type'] == 'edit_cell' else 'active_cell_changed' location = (self._df.index[content['row_index']], content['column']) @@ -1436,25 +1444,27 @@ def _handle_qgrid_msg_helper(self, content): if col_info['type'] == 'datetime': val_to_set = pd.to_datetime(val_to_set) - old_value = self._df.loc[location] self._df.loc[location] = val_to_set query = self._unfiltered_df[self._index_col_name] == \ content['unfiltered_index'] self._unfiltered_df.loc[query, content['column']] = val_to_set - self._notify_listeners({ - 'name': 'cell_edited', + result = { + 'name': event_name, 'index': location[0], 'column': location[1], - 'old': old_value, 'new': val_to_set, 'source': 'gui' - }) + } + if content['type'] == 'edit_cell': + old_value = self._df.loc[location] + result['old'] = old_value + self._notify_listeners(result) except (ValueError, TypeError): - msg = "Error occurred while attempting to edit the " \ + msg = "Error occurred while attempting to {received_event} the " \ "DataFrame. Check the notebook server logs for more " \ - "information." + "information.".format(received_event=received_event) self.log.exception(msg) self.send({ 'type': 'show_error',