This is a migrated thread and some comments may be shown as answers.

databinding issue when adding items

3 Answers 46 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Bridge24
Top achievements
Rank 1
Iron
Bridge24 asked on 03 Oct 2019, 02:58 PM

Hi, I have a dropdown that I need to add available values in it while it is already loaded and have a selected item.

Look at my sample:

https://dojo.telerik.com/@foxontherock/ulONexoh/2

I just create an observable Array, bind it to my datasource, and run it.  I select an item.

Then, I try to add a new one, using databinding, so I "push" it to the observableArray.

These are some issues I have:

When I open the dropdown after adding items, all the selections seems to be reversed (orange / gray)

If I don't reselect a new item, the last one - 1 is selected (reversed). 
But the real selected one seems to be the last (new one) when calling the .text() method.

Also, if I call select(id-of-already-selected-item), it switch to it, but when i open the combo, all colors are reversed.

I also tried to:
combo.refresh()
combo.datasource.data(original list containing new item)

combo.datasource.data(copy of original list from .toJSON())
I never had any good results.
Looks like I need to destroy and recreate the combo from scratch if I want to add a new item !!

Thank you

3 Answers, 1 is accepted

Sort by
0
Bridge24
Top achievements
Rank 1
Iron
answered on 03 Oct 2019, 03:08 PM

I just tried using the dataSource transport read method instead, with the same results.
https://dojo.telerik.com/@foxontherock/enijuRAF

 

0
Aleksandar
Telerik team
answered on 07 Oct 2019, 11:10 AM

Hello Daniel,

This article in the documentation section provides guidelines on adding a new item to the DropDownList dataSource and the following demo provides and example implementation of the guidelines.

Adding an id field to the objects stored in the observable array would resolve the unexpected behavior that is reported. You can find an updated version of the provided dojo here

Let me know if the proposed solution works for you.

Regards,
Aleksandar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Bridge24
Top achievements
Rank 1
Iron
answered on 11 Oct 2019, 06:42 PM
Ohhh my fault, I forgot the ids!!! Thank you.
Tags
DropDownList
Asked by
Bridge24
Top achievements
Rank 1
Iron
Answers by
Bridge24
Top achievements
Rank 1
Iron
Aleksandar
Telerik team
Share this question
or