1

I'm using the bwu-grid and want to have the delete key to delete rows. Here is the code I have right now:

_grid.onKeyDown.listen((e) {

  print("onKeyDown ${e.keyCode}");
  if(e.keyCode == 46)
  {
    var rows = _grid.getSelectedRows();
    for (var i = 0, l = rows.length; i < l; i++) {
      var item = _dataView.getItem(rows[i]);
      var rowid = item["id"];
      _dataView.deleteItem(rowid);

      // This should probably be handled in another event?
      _grid.invalidate();
      _grid.render();

    }
  }
});

It works but the problem is that if I enter edit mode on a cell and hit the delete key to delete a character inside the cell then the same code gets run and deletes the whole row. So I guess I need a way to determine if the cell is in edit mode or not. Or maybe I am going about this the wrong way?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Jonas Kello
  • 1,178
  • 2
  • 13
  • 25
  • Do you have a custom editor? You should probably consume the event there (`preventDefault`, `stopPropagation`). – Günter Zöchbauer Dec 20 '14 at 11:51
  • I'm using the built-in TextEditor(). – Jonas Kello Dec 20 '14 at 23:19
  • Sorry, I just ported the code, I don't it all by hart... I guess the best option is to create your own TextEditor class (extend TextEditor) and consume the event there. I'm just back from vacation. I'll take a look an see if I can provide more details. – Günter Zöchbauer Dec 21 '14 at 09:05
  • Thanks, ok I will try a separate TextEditor. To add some more info, I ported the delete row on delete key code from this SlickGrid question: http://stackoverflow.com/questions/9126772/slickgrid-cannot-delete-added-rows-but-only-existing-ones-what-am-i-doing-wron – Jonas Kello Dec 22 '14 at 10:00

0 Answers0