EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: thecyberzone on February 08, 2015, 09:00:52 PM



Title: Counting No. of rows populated in Combobox
Post by: thecyberzone on February 08, 2015, 09:00:52 PM
A Combobox editor in a editable datagrid is invoked as follows :

Code:
	 				onBeginEdit: function(index,row){
var ed = $(this).datagrid('getEditor', {index:index,field:'trgdate'});
       if (ed){
           $(ed.target).combobox('reload','rating.getPlan.php?yr='+yr+'&trgcode='+row.trgcode);
           
                                            // Now here I want to count the no. of rows populated in combobox,
                                            // so that if no. of rows is zero I can configure the editor as simple datebox instead of combobox

                                            var x = $(ed.target).combobox('getValues');
           console.log(x.length);
                                            if (x.length<1) {
                                                $(ed.target).editor = 'datebox';
                                            }
           
       }
   },

Now how can I count the number of rows present in combobox, so that if it becomes 0 I can change the editor type and put a simple datebox instead.

Thanks in advance.


Title: Re: Counting No. of rows populated in Combobox
Post by: thecyberzone on February 09, 2015, 09:58:27 AM
I have changed the following line as follows:

var x = $(ed.target).combobox('getData');

instead of

var x = $(ed.target).combobox('getValues');

still x.length does not give the length of rows in combobox.

Please help me.


Title: Re: Counting No. of rows populated in Combobox
Post by: stworthy on February 09, 2015, 08:17:50 PM
To get the loaded row count, please call $(ed.target).combobox('getData') after loaded data successfully. Please refer to the code below.
Code:
$('#dg').datagrid({
    onBeginEdit: function(index,row){
        var field = 'productid';
        var ed = $(this).datagrid('getEditor', {index:index,field:field});
        $(ed.target).combobox({
            value: row[field],
            url: 'products.json',
            onLoadSuccess: function(data){
                console.log(data.length)
            }
        });
    }
})


Title: Re: Counting No. of rows populated in Combobox
Post by: thecyberzone on February 10, 2015, 03:45:18 AM
The way you have told works, but what I actually want is whenever after loading success it returns 0 rows populated, i.e., data.length == 0, at that moment I want to change the column editor type from combobox to datebox, so that I can enter Date manually, not from combo.


Title: Re: Counting No. of rows populated in Combobox
Post by: thecyberzone on February 10, 2015, 08:57:30 AM
I have done following coding :

Code:
onBeginEdit: function(index,row){	        
                var field = 'trgdate';
        var ed = $(this).datagrid('getEditor', {index:index,field:field});
        $(ed.target).combobox({
            value: row[field],
            url: 'rating.getPlan.php?yr='+yr+'&trgcode='+row.trgcode,
            onLoadSuccess: function(data){
                // alert(data.length);
                if (data.length == 0) {

// var colDate = $(this).datagrid('getColumnOption', 'trgdate');
// colDate.editor = 'datebox';

$(ed.target).editor = 'datebox';
}
            }
        });
       
    },

But this does not work, although no. of rows populated in combobox (data.length) can be access easily. Problem is that I cannot change the editor type of that cell from combobox to datebox. Perhaps, this cannot be possible within beginEdit event, because already editing is going on, perhaps have to make endEdit first, then have to change editor type to datebox and again have to invoke beginEdit. Better to invoke the same routine in another event like BeforeEdit or something else custom made.