EasyUI Forum

General Category => General Discussion => Topic started by: contestant on April 05, 2015, 08:05:51 AM



Title: Select current item in combobox on editing datagrid row
Post by: contestant on April 05, 2015, 08:05:51 AM
Hello

I have a problem on editing row of datagrid, When editing of row is began, Combo box has been not selected default value.

Please guide me!

Thanks  ;)


Title: Re: Select current item in combobox on editing datagrid row
Post by: stworthy on April 05, 2015, 06:07:09 PM
What do you mean the 'selected default value'? Normally, you need to set the 'valueField' and 'textField' properties correctly when using the combobox editor. You also can change the combobox's value when editing a row.
Code:
$('#dg').datagrid({
onBeginEdit: function(index,row){
var ed = $(this).datagrid('getEditor', {index:index,field:'productid'});
if (ed){
$(ed.target).combobox('setValue', 'RP-LI-02');
}
}
})


Title: Re: Select current item in combobox on editing datagrid row
Post by: contestant on April 05, 2015, 11:53:39 PM
Thank's for your answer

I fixed this problem with a better solution, with an extra option parameter for datagrid, because my field value there is in another database field.

This solution automatically work in "onBeginEdit" event of datagrid;
Example:

Code:
var editors = $(this).edatagrid('getEditors', index);
                   
                $.each(editors, function() {
                    if( this.type == 'combobox' ){
                        var opts = $(this.target).combobox('options');
                        $(this.target).combobox('setValue', row[ ( opts.defaultValueField != '' ? opts.defaultValueField : this.field ) ]);
                    }
                });