Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using Handsontable how to force a selected cell into edit mode?

Handsontable provides some nice hooks for when a cell is selected but I can't seem to figure out way to get it to allow me to force a cell into edit mode when it has been selected.

I can detect the cell selection like this:

Handsontable.PluginHooks.add( 'afterSelection', function( row, column ) {
    var current_td = this.getCell( row, column );
});

And from there I can even obtain the cell element that was selected. But from there I can't seem to trigger the cell into edit mode (where it has an actively selected textarea field inside of it). This is normally triggered by a double click. Doing the obvious doesn't seem to work:

Handsontable.PluginHooks.add( 'afterSelection', function( row, column ) {
    var current_td = this.getCell( row, column );

    $(current_td).dblclick();
});

Anyone else ever done this or have thoughts on how I might get it to work?

like image 724
Jamie Poitra Avatar asked Aug 18 '13 21:08

Jamie Poitra


2 Answers

For anyone intersted in this question, now there is a better programmable way to achieve the same result.

this.selectCell(row, col);
this.getActiveEditor().beginEditing();

This selects the (row, col) cell and enters edit mode (i.e. same as double click or pressing F2/Enter).

like image 111
Milan Milanov Avatar answered Nov 14 '22 09:11

Milan Milanov


And I believe I've answered my own question:

Handsontable.PluginHooks.add( 'afterSelectionEnd', function() { 
        f2_event = $.Event( 'keydown', { keyCode: 113 } );
        this.$table.trigger(f2_event);
});

That seems to do the trick.

like image 30
Jamie Poitra Avatar answered Nov 14 '22 11:11

Jamie Poitra