EasyUI Forum
July 05, 2024, 04:56:29 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: Column editor attribute in datagrid  (Read 6386 times)
officecode
Jr. Member
**
Posts: 69


View Profile Email
« on: November 28, 2018, 09:22:00 PM »

I am now trying to automatically generate a non-hidden column form by clicking on the row in the datagrid. Since some columns have editors set up, some don't, so I use eval to generate them dynamically.
The sample code is as follows:
Code:

        var frm = $('#dlg>form');
var fields = $('#test').datagrid('getColumnFields');
fields.forEach(function(v){
var col = $('#test').datagrid('getColumnOption',v);
                if(col.title && !col.hidden){
var el = '<p><input id="' + v + '" name="' + v + '"></p>';
$(el).appendTo(frm);
if(col.editor){
var comp = "$('#' + v).";
if(typeof col.editor == 'string'){
comp += col.editor;
                                }else{
comp += col.editor.type;
                                }
comp += "({label:'" + col.title + "',labelAlign:'right',[b]onChange:function(){}[/b]})"
eval(comp);
                        }else{
$('#' + v).textbox({label:col.title,labelAlign:'right',disabled:true})
                        }
}
});
frm.children('p').css('float','left');
frm.form('load',row);


But there is a problem with this: if you add the onChange event code to eval, it's too complicated. The key is, in the onChange event, how to call the setValue method of the datagrid editor component? My goal is to fill the data into the editor once the form data has changed.
I really don't want to use eval. Is there any better way to solve this problem? Looking forward to your help, thank you!
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: November 29, 2018, 02:30:48 AM »

Please refer to this example http://code.reloado.com/akahad/edit#preview
Logged
officecode
Jr. Member
**
Posts: 69


View Profile Email
« Reply #2 on: November 29, 2018, 08:06:47 PM »

Well, this example gave me a lot of inspiration, thank you.
But the question is, how do I write code in the form's onChange event? Because, to assign the value in input to the cell in the datagrid, you still need to get the editor of the datagrid column, otherwise you can not use the editor's setValue method.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: November 30, 2018, 06:23:30 AM »

You can attach the 'onChange' event on each field component.
Code:
var opts = {
label: col.title,
labelAlign: 'right',
width: '100%',
field: field,
onChange: function(value){
//...
}
}

Or retrieve the editor value in the form component.
Code:
frm.form({
onChange:function(target){
  var editor = $(target);
  //...
}
})
Logged
officecode
Jr. Member
**
Posts: 69


View Profile Email
« Reply #4 on: November 30, 2018, 08:19:41 AM »

You can attach the 'onChange' event on each field component.
Or retrieve the editor value in the form component.

I understand this.
The key is how to use the setValue method, because I have to know the type of the editor.

Code:
frm.form({
onChange:function(target){
  var editor = $(target);
      var v = $(target).val();
  //How to write the value of this variable v to the datagrid editor through the setValue method?
}
})

Sorry, my English is not good, I don't know if you understand what I mean, thank you.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 on: December 01, 2018, 12:13:20 AM »

Please look at this example http://code.reloado.com/akahad/2/edit#preview
Logged
officecode
Jr. Member
**
Posts: 69


View Profile Email
« Reply #6 on: December 01, 2018, 08:27:15 AM »


This example is very good, thank you for your reply.
I also tested for a long time, as if it was more difficult to handle in the form's onChange event.
There is a suggestion: if possible, add a field attribute to all form components to directly bind fields in the datagrid. This property not only automatically inherits the column properties in the datagrid, but also makes synchronous modifications on the data.
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!