EasyUI Forum
May 02, 2024, 11:18:16 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: Using onAdd to set default values in an Editable Datagrid  (Read 3281 times)
mschnitter
Newbie
*
Posts: 8


View Profile
« on: January 03, 2021, 09:53:30 PM »

Hello,

I'm using an Editable Datagrid to perform some basic CRUD functions. I would like to set default values when a new row is added to the datagrid.

I read through the documentation and saw that the onAdd event seemed like the perfect place to do this.

Created the following method:

onAdd: function(index,row){
                  row.Key = 'U';             
                  row.Status = 'N';
                }
Key and Status are two columns in my datagrid.

When I run my code, nothing happens. When I step through with the browser JS debugger, it looks like row is not used the same way as other examples that have a seen. I haven't found an example of using onAdd to set default values when a row is added in an edatagrid. I'm beginning to wonder if I'm approaching this the wrong way.

Any Thoughts?

Thanks
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: January 05, 2021, 12:24:52 AM »

If you have the editor on the column, you can get the editor and set its value after adding a row.
Code:
onAdd: function(index,row){
  var ed = $(this).edatagrid('getEditor', {index:index,field:'Key'});
  $(ed.target).textbox('setValue', 'U')
}

You can also set any row values before editing a row.
Code:
onBeforeEdit: function(index,row){
  if (row.isNewRecord){
    row.Key = 'U'
  }
},
Logged
mschnitter
Newbie
*
Posts: 8


View Profile
« Reply #2 on: January 05, 2021, 07:47:09 AM »

Hi Jarry,

Thank You!! That did the trick. I played with the $(ed.target) reference in the debugger, and found that very helpful. I was able to set defaults for the fields I needed in the onAdd event.

Thanks Again
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!