onKeyPress

with regards to the onKeyPress event…

is there a way to know what key was pressed?



basically what im trying to do is like an excel-like table…

if a cell is selected and a key is pressed edit the cell…im avoiding some keys like fkey, enter, shift…etc…basically allow only character key…and also differentiate character key from eneter key…



and is there a way also of detaching an event…presently i have attached an onKeyPress event on my grid…and when it is triggerred the current cell will be opened for editting…but then, when i try to edit the cell by entering values…it seems like the onKeyPress event is triggerred again…it made the onKeyPress event ineffective.,.



thank you in advance…hope you can help…

is there a way to know what key was pressed?

Sure you receive key code as event parameter

mygrid.attachEvent(“onKeyPress”,function(keycode,ctrl,shift,event_object){
    alert(keycode);
    return true;
});

>>if a cell is selected and a key is pressed edit the cell…
Basically grid already has such functionality. Just include in your project next js file
    codebase/ext/dhtmlxgrid_keymap_excel.js
It will change keymapping to excel like one, which include auto-edit on text typing


>>and is there a way also of detaching an event
Basically you can use
    var id = grid.attachEvent(…
    …
    grid.detachEvent(id);   //detach previously attached event

But in your scenario the next logic will be a more simple solution

mygrid.attachEvent(“onKeyPress”,function(keycode,ctrl,shift,event_object){
    if (this.editor) return true; //  skip any logic if grid in edit mode

    …

    return true;

});