Skip to content
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

Add support for qgrid active_cell_changed from SlickGrid onActiveCellChanged #234

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions js/src/qgrid.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 18 additions & 8 deletions qgrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def on(names, handler):
[
'instance_created',
'cell_edited',
'active_cell_changed',
'selection_changed',
'viewport_changed',
'row_added',
Expand Down Expand Up @@ -661,6 +662,7 @@ def on(self, names, handler):

[
'cell_edited',
'active_cell_changed',
'selection_changed',
'viewport_changed',
'row_added',
Expand All @@ -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.

Expand Down Expand Up @@ -1426,35 +1433,38 @@ 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'])

val_to_set = content['value']
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',
Expand Down