EasyUI Forum
May 05, 2024, 11:56:38 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to set the "Escape" key to UNDO and Leaving Cell editing in DataGrid ?  (Read 7750 times)
Jonny
Newbie
*
Posts: 38


View Profile Email
« 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
 

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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');
Logged
Jonny
Newbie
*
Posts: 38


View Profile Email
« Reply #2 on: May 22, 2015, 09:43:00 PM »

Hello Stworthy,

       Thank you for giving sample code, it works ! Smiley


Regards,
Jonny

« Last Edit: May 22, 2015, 11:37:52 PM by Jonny » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!