Skip to content

Commit

Permalink
Merge pull request quantopian#58 from blink1073/fix-indexing
Browse files Browse the repository at this point in the history
Fix indexing in the presence of sorting or filtering
  • Loading branch information
TimShawver committed Feb 22, 2016
2 parents 81ff960 + c97cb96 commit 4b77bdb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion qgrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def add_row(self, value=None):
double_precision=precision)
msg = json.loads(row_data)
msg[self._index_name] = str(last.name)
msg['id'] = str(last.name)
msg['slick_grid_id'] = str(last.name)
msg['type'] = 'add_row'
self._dirty = True
self.send(msg)
Expand Down
15 changes: 11 additions & 4 deletions qgrid/qgridjs/qgrid.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,21 @@ define([path + "widgets/js/widget", path + "widgets/js/manager"], function(widge
// set up callbacks
sgrid.onCellChange.subscribe(function(e, args) {
var column = columns[args.cell].name;
var msg = {'row': args.row, 'column': column,
var id = args.grid.getDataItem(args.row).slick_grid_id;
var row = Number(id.replace('row', ''))
var msg = {'row': row, 'column': column,
'value': args.item[column], 'type': 'cell_change'};
that.send(msg);
});

sgrid.onSelectedRowsChanged.subscribe(function(e, args) {
var rows = args.rows;
var msg = {'rows': args.rows, 'type': 'selection_change'};
var rows = [];
var grid = args.grid;
for (var r = 0; r < args.rows.length; r++) {
var id = grid.getDataItem(args.rows[r]).slick_grid_id;
rows.push(Number(id.replace('row', '')));
}
var msg = {'rows': rows, 'type': 'selection_change'};
that.send(msg);
});
},
Expand All @@ -165,7 +172,7 @@ define([path + "widgets/js/widget", path + "widgets/js/manager"], function(widge
return;
}
var data = sgrid.getData().getItem(cell.row);
grid.data_view.deleteItem(data.id);
grid.data_view.deleteItem(data.slick_grid_id);
msg = {'type': 'remove_row', 'row': cell.row, 'id': data.id};
this.updateSize();
this.send(msg);
Expand Down

0 comments on commit 4b77bdb

Please sign in to comment.