EasyUI Forum
April 20, 2024, 06:14:46 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: Is it possible to change editor for column when row is in edit mode  (Read 3115 times)
glarsen
Newbie
*
Posts: 39


View Profile Email
« on: April 09, 2018, 07:07:44 AM »

I would like to change the editor of a datagrid column when another column in the row changes using a combobox.

This line runs:   col.editor = checkBoxEditor 

and it changes the editor of the object (see attached) but does not update the datagrid.


            {field:'licenseType', title:'License', fixed: true, width: 120,
                formatter:function(value,row){
                    return row.licenseType;
                },
                editor:{
                    type:'combobox',
                    options:{
                        limitToList: true,
                        valueField:'licenseType',
                        textField:'label',
                        method:'get',
                        mode:'local',
                        data: [{
                              label: 'Administrator',
                              licenseType: 'Administrator'
                            },{
                              label: 'Analyst',
                              licenseType: 'Analyst'
                            },{
                              label: 'Author',
                              licenseType: 'Author'
                            },{
                              label: 'Consumer',
                              licenseType: 'Consumer'
                            }],
                        required:true,
                        onChange:function(newValue, oldValue) {
                            if (oldValue != '') {
                                var col = $('#userGrid').datagrid('getColumnOption', 'modelItem');
                                if (newValue == 'Analyst') {
                                    col.editor = checkBoxEditor;
                                } else {
                                    col.editor = null;
                                }
                            }
                        }
                    }
                }
            },


Thanks for any assistance.

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


View Profile Email
« Reply #1 on: April 09, 2018, 07:32:25 PM »

To change the editor, please reset the 'editor' property and call 'beginEdit' method to edit the row again. Please try this code.
Code:
$('#dg').datagrid({
onBeginEdit: function(index,row){
var ed1 = $(this).datagrid('getEditor', {index:index,field:'licenseType'});
var col = $(this).datagrid('getColumnOption', 'modelItem');
$(ed1.target).combobox({
value: row. licenseType,
onChange: function(value){
if (value == 'Analyst'){
col.editor = {type:'checkbox',options:{on:'P',off:''}}
} else {
col.editor = null;
}
setTimeout(function(){
$('#dg').datagrid('endEdit', index).datagrid('beginEdit', index);
},0);
}
})
}
})
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!