EasyUI Forum

General Category => General Discussion => Topic started by: Jonny on May 21, 2015, 10:13:15 PM



Title: How to set the "Escape" key to UNDO and Leaving Cell editing in DataGrid ?
Post by: Jonny on May 21, 2015, 10:13:15 PM
Dear All,

            Base on Demo -> Cell Editing in DataGrid:
http://www.jeasyui.com/demo/main/index.php?plugin=DataGrid&theme=default&dir=ltr&pitem=
 
Is there any possibility to set "ESCAPE" key or any key to UNDO changes and leave the cell editing?

Please help me if anyone expert on this..
Thanks in advance.
 
Regards,
JONNY
 



Title: Re: How to set the "Escape" key to UNDO and Leaving Cell editing in DataGrid ?
Post by: stworthy on May 22, 2015, 05:25:30 PM
Bind the 'keydown' event on the editing box. When pressing the ESC key, cancel the current editing action. Please refer to the following code.
Code:
$('#dg').datagrid({
    onBeginEdit:function(index,row){
        var dg = $(this);
        var ed = dg.datagrid('getEditors',index)[0];
        if (!ed){return;}
        var t = $(ed.target);
        if (t.hasClass('textbox-f')){
            t = t.textbox('textbox');
        }
        t.bind('keydown', function(e){
            if (e.keyCode == 13){
                dg.datagrid('endEdit', index);
            } else if (e.keyCode == 27){
                dg.datagrid('cancelEdit', index);
            }
        })
    }
}).datagrid('enableCellEditing');


Title: Re: How to set the "Escape" key to UNDO and Leaving Cell editing in DataGrid ?
Post by: Jonny on May 22, 2015, 09:43:00 PM
Hello Stworthy,

       Thank you for giving sample code, it works ! :)


Regards,
Jonny