I am trying to delete a row on pressing the delete key. However, I am unable to connect individual rows to a key listener. I tried using dojo.connect(row1, "onkeyup", myHandler) to connect a particular row to a custom handler, but the handler never gets called. Is there some other way of doing this? Does the TreeGrid support key events or will I have to get the dom nodes and connect event handlers to them?
I would go about it from a different angle. dojox.grid.TreeGrid
itself has an onKeyUp
event that would be useful. It detects any key being released when the grid itself is focused. You could attach a handler to the entire TreeGrid, then get the selected row, and delete it with that information. Something like the following:
dojo.connect(registry.byId("grid"), "onKeyUp", function(event) {
if (event.keyCode == 46) { // The keycode for the delete key is 46
var selectedRow = this.selection.getSelected(); // Get selected item
// Do your deletion here.
}
}