Activate dojo dgrid editor using keyboard

Triggering edit mode in dojo dgrid with mouse event is easy. Here's what I have done:

editor({field: "checkNumber",label: "Check Number",editOn: "click"})

However, i want to trigger edit mode using keyboard. Specifically, i want to go into edit mode when I press the space key. How can I programmatically set a cell to 'edit mode' or 'non-edit mode'?

Answers


When you add one or more editor columns to a grid, it makes the edit method available on the grid instance, which you can call with a cell element (or event referencing one) to programmatically shift focus to the editor for the cell.

Meanwhile, the Keyboard mixin has an addKeyHandler method which you can use to add handlers to respond to keydown events for particular keys.

Combining these two things, you can easily do the following to cause the grid to edit the focused cell when space is pressed:

grid.addKeyHandler(32, function (event) {
    grid.edit(event);
});

(edit should have no effect for cells in non-editor columns.)

An alternative solution could be to create an extension event which triggers either on mouse click or on space keypress, and pass that to editOn instead of 'click'.


var grdobj = dijit.byId("...");    
var editCell=grdobj.cell(rowNo, "checkNumber");
grdobj.edit(editCell);

Instead of cell function, you could make use of right, left, up, or down functions.

Hope that helps.


Need Your Help