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:
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!