EasyUI Forum
March 29, 2024, 03:13:57 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: Save data on Edatagrid on enter key press.  (Read 6035 times)
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« on: March 10, 2017, 08:42:17 AM »

I have the following code for my edatagrid. And it works fine. But I need a feature: save data on hitting Enter Key.

Quote
$('#dg').edatagrid({
                url: 'get_customer.php',
                saveUrl: '../controller/save_customer.php',
                updateUrl: '../controller/update_customer.php',
                destroyUrl: '../controller/destroy_customer.php'
});
Logged
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« Reply #1 on: March 10, 2017, 09:20:52 AM »

This code works fine. But I want reload the datagrid and add new row. Is that possible and How?

Quote
onBeginEdit: function(index,row){
                  var dg = $(this);
                  var editors = dg.edatagrid('getEditors',index);
                  for(var i=0; i<editors.length; i++){
                    $(editors.target).textbox('textbox').bind('keydown',function(e){
                      if (e.keyCode == 13){
                        dg.edatagrid('endEdit', index);
                        // if (index<dg.edatagrid('getRows').length-1){
                        //   dg.edatagrid('selectRow', index+1).edatagrid('beginEdit', index+1);
                        // }
                        //$('#dg').edatagrid('reload');
                        $('#dg').edatagrid('addRow');
                      }
                    });
                  }
                  if (editors.length){
                    $(editors[0].target).textbox('textbox').focus();
                  }
              }
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 on: March 12, 2017, 07:53:51 AM »

What is the purpose of calling the 'reload' method? Once you call the 'saveRow' method, the editing data is updated to the row and saved to the server.
Logged
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« Reply #3 on: March 15, 2017, 10:00:20 AM »

Yes I learnt that this is not necessary. It's only my assumption before I actually tested it. I added
Code:
autoSave:true,
and that was exactly I was looking for. It worked fine now. Thanks.
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!