EasyUI Forum
November 05, 2025, 09:40:49 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: Counting No. of rows populated in Combobox  (Read 13244 times)
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« 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.
« Last Edit: February 08, 2015, 09:05:01 PM by thecyberzone » Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #1 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.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #2 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)
            }
        });
    }
})
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #3 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.
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #4 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.
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!