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.

Add Items to ListBox

Thread ID:

Created:

Updated:

Platform:

Replies:

132669 Sep 14,2017 12:02 PM Sep 19,2017 08:09 AM JavaScript 5
loading
Tags: ejListBox
Carsten Buchmann
Asked On September 14, 2017 12:02 PM

Hi,
I try to add some items to a listbox with value and text:

@(Html.EJ().ListBox("LocationsListBox")
                    .ListBoxFields(f => f.Text("Name").Value("Value")
                    .ClientSideEvents(e => e.CheckChange("LocationsChanged"))
                    .Width("100%")
                    )


locations.forEach(function(location){
                listbox.ejListBox("addItem", {Value: location.Id, Name: location.Name + " " + location.PostCode + " " + location.City });


And I get this:


How can add a object to the listbox?

Kind regards,
Carsten

Arun Palaniyandi [Syncfusion]
Replied On September 15, 2017 06:06 AM

Hi Carsten, 

Sorry for the inconvenience caused. 

We were able to reproduce the reported issue with addItem, which has been already fixed in the Volume 3, 2017(15.3.0.26) version and above. Hence we suggest you to upgrade to our latest version to get this issue resolved. 




Regards, 
Arun P 


Carsten Buchmann
Replied On September 15, 2017 10:22 AM

Hi Arun,

thanks. The update made my day.

Regards,

Carsten


Arun Palaniyandi [Syncfusion]
Replied On September 18, 2017 03:23 AM

  
Hi Carsten,  
  
We are glad that our solution has resolved your issue.  
  
Please let us know if you have any queries in future.  
  
Regards,  
Arun P.  


Carsten Buchmann
Replied On September 18, 2017 09:38 AM

Hi Arun,

unfortunately it doesn't work. Indeed I can add items, but they not stored as expected. I can't get the value back out of the selected items:

http://jsplayground.syncfusion.com/iy5bkvzw

In the property text and value are the same values.

Kind regards,

Carsten


Arun Palaniyandi [Syncfusion]
Replied On September 19, 2017 08:09 AM

Hi Carsten,  
     
Thanks for your update.   
  
We have checked the reported scenario and we can reproduce your issue. As you have said, items can be added but cannot be stored and this is because you have not given the datasource property to the ListBox. Adding items to Listbox when the datasource is not given, will add the items by taking the given object’s text value through appending the text in the ListBox <ul>. Also, you cannot take the value field because the given text value is considered as the value field in this case. So, we suggest to bind an empty datasource to the ListBox and then you can add items to it. Please find the below code snippets.   
 
   
$("#selectgroup").ejListBox({   
           dataSource:[],    // Bind an empty datasource   
            fields: {   
            text: "Name" ,value:"Value" }   
        }   
                                   );   
        locations.forEach(function(location){   
          $("#selectgroup").ejListBox("addItem", {   
            Name: location.Name, Value: location.Id  });   
        });     
   
   
   
Please try the given workaround, and if you still face any issue let us know, so that we would help you out better.   
   
Regards,   
Arun P.   


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.

;