We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Total items count?

Thread ID:

Created:

Updated:

Platform:

Replies:

132731 Sep 18,2017 03:31 PM Mar 9,2018 08:00 AM ASP.NET MVC 7
loading
Tags: DropDownList
Michael Lambert
Asked On September 18, 2017 03:31 PM

How do I get the total number of items in a dropdown list?


Prince Oliver [Syncfusion]
Replied On September 19, 2017 07:15 AM

Hi Michael 

Thank you for contacting Syncfusion forums. 

You can get the total number of items in a DropDownList from the getListData method. Kindly refer to the following code snippet.  

<script type="text/javascript"> 
    function buttonclick(){ 
        var target = $('#skillsets').data("ejDropDownList"); // accessing the control's instance 
        alert("Number of items: "+target.getListData().length); //accessing number of items from getListData method 
    } 
</script> 

Kindly refer to the following playground sample: http://jsplayground.syncfusion.com/qjpiump4 

Regards, 
Prince 


Michael Lambert
Replied On September 19, 2017 07:31 PM

I tried that and get this error:


I tried grp1.getListData.length (without paras) but the value is always 0.


Prince Oliver [Syncfusion]
Replied On September 20, 2017 12:26 AM

Hi Michael  

Thank you for your update. 

The getListData is a method which returns the list of items present in the DropDownList, so grp1.getListData.length (without parenthesis) will return value 0. Kindly refer to the following UG documentation link: https://help.syncfusion.com/api/js/ejdropdownlist#methods:getlistdata 

You can update your code to validate the getListData method whether it is empty or not before accessing length. Kindly refer to the following code snippet. 

<script > 
    var grp1 = $('#ddlBUGrp2').data("ejDropDownList"); // accessing control's instance 
    var x = ej.isNullOrUndefined(grp1.getListData()) ? 0 : grp1.getListData().length; //if the getListData is undefined, then return 0. 
</script> 

Regards, 
Prince 



Michael Lambert
Replied On September 20, 2017 04:47 PM

That works, but now run into another interesting thing:

var grp2 = $("#ddlBUGrp2").data("ejDropDownList");

   $('#ddlBUGrp2').ejDropDownList({ dataSource: data});  //data is a list with say 4 items
   var numItems1 = ej.isNullOrUndefined(grp2.getListData()) ? 0 : grp2.getListData().length;  //numItems1 = 4 which would be correct

  $('#ddlBUGrp2').ejDropDownList({ dataSource: null});
  var numItems2 = ej.isNullOrUndefined(grp2.getListData()) ? 0 : grp2.getListData().length;  //numItems2 still = 4 shouldn't it be 0;

Mike



Prince Oliver [Syncfusion]
Replied On September 21, 2017 01:22 AM

Hi Michael   

Thank you for your update. 

Alternatively, you can use our internal _getLi method which returns all the <li> elements in the DropDownList’s popup wrapper. Kindly refer to the following code snippet. 

<script type="text/javascript">   
    var grp2 = $("#ddlBUGrp2").data("ejDropDownList"); 
    $('#ddlBUGrp2').ejDropDownList({ dataSource: data});  
    var numItems1 = grp2._getLi().length;   
    $('#ddlBUGrp2').ejDropDownList({ dataSource: null}); 
    var numItems2 = grp2._getLi().length;  
</script> 


Regards, 
Prince 


pradeep kurmar
Replied On March 7, 2018 11:20 AM

Hi Michael 

Thank you for contacting Syncfusion forums. 

You can get the total number of items in a DropDownList from the getListData method. Kindly refer to the following code snippet.  

<script type="text/javascript"> 
    function buttonclick(){ 
        var target = $('#skillsets').data("ejDropDownList"); // accessing the control's instance 
        alert("Number of items: "+target.getListData().length); //accessing number of items from getListData method 
    } 
</script> 

Kindly refer to the following playground sample: http://jsplayground.syncfusion.com/qjpiump4 

Regards, 
Prince 


HELLO


Ilakkiya Baskar [Syncfusion]
Replied On March 9, 2018 08:00 AM

Hi Michael, 
 
Thank you for your patience.  
 
We have validated the reported issue at our end. We have considered it as a defect and logged a defect report. The fix for the issue will be included in Vol-1 2018 service pack -1 release, which will be available by the end of March  2018. We appreciate your patience until then.  
 
Regards,  
Ilakkiya B 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;