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.

dynamic loading of list items

Thread ID:

Created:

Updated:

Platform:

Replies:

128486 Jan 25,2017 08:46 AM Jan 25,2017 11:17 AM JavaScript 2
loading
Tags: ejDropDownList
Michael Salzlechner
Asked On January 25, 2017 08:46 AM

We have tried to create a dropdownlist that fills dynamically

tried to create a dropdownlist empty first and then use additem to add items

$('#selectCar').ejDropDownList({
                targetID: "carsList",
                watermarkText: "Select a car",
                width: "100%"
            });

var target = $('#selectCar').data("ejDropDownList");
var newitems = [
   { text: "India"},
   { text: "Pakistan"},
   ];
           
    target.addItem(newitems  );

this fails. looks like you cannot create a dropdownlist without items
tried it with adding an empty item first this works but I cant remove the empty items

I need to be able to change the items in the list dynamically

thanks




this



Michael Salzlechner
Replied On January 25, 2017 09:11 AM

looks like I may have solved this but if there is a better way let me know

here is what I ended up with

1) create the dropdownlist with an item with blank text
2) use the dataSource option to change the data dynamically

 $('#selectCar').ejDropDownList({
    dataSource: [{text:""}],
                targetID: "carsList",
                watermarkText: "Select a car",
                width: "100%"
            });

....

var newitems = [
   { text: "India"},
   { text: "Pakistan"},
   ];
          
  target.option("dataSource", newitems);











Karthikeyan Viswanathan [Syncfusion]
Replied On January 25, 2017 11:17 AM

Hi Michael Salzlechner,       
 
Thanks for contacting Syncfusion support. 
 
No Need to assign empty value to DropDownList. It will be rendered also without any datasource. Please find the below code snippet: 
 
 
<code> 
 
$('#bikeList').ejDropDownList({ 
                fields: { id: "empid", text: "text", value: "text" } 
            }); 
          $("#btn").click(function(){ 
                                                var inst = $('#bikeList').ejDropDownList("instance"); 
                                                inst.option("dataSource", BikeList); 
                                                 
                                    }); 
 
</code> 
 
 
JS Playground sample link: http://jsplayground.syncfusion.com/zg12b3yt  
 
Please let us know if you have any other queries.  
   
Regards,    
Karthikeyan V.   


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.

;