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

Add items afer databind

7 Answers 897 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 11 Dec 2011, 08:12 PM
After my DS rebinds the combo boxes I need to add a couple items at index 0 on the combos.

...so now I'm pretty sure I could just jQuery them in there...is that the proper way??

**EDIT** I'm sorry, this should be in the DropDownList area!...same question though :)

Steve

7 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 13 Dec 2011, 01:18 PM
Hello Steve,

 
You can use the data() method of the DateSource. You should modify current list of items and pass it to the data() method.

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 17 Dec 2011, 05:49 PM
Could you give me a hand Georgi?

I tried adding the item into the change event of the DS, but it (clearly) ends up in an infinite change loop :) Which means I can't modify the data of the DS directly right?

So are you then saying I need to NOT bind my dropdowns to a DS and instead manually add the data in?
0
Georgi Krustev
Telerik team
answered on 20 Dec 2011, 10:54 AM
Hello Steve,

 
Yes, your observations are correct. The data cannot be modified in the change event of the DataSource. Actually the data() method triggers the change event. You should manually add the data. I created a simple jsFiddle demo, which shows what I mean.

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Cory Deppen
Top achievements
Rank 1
answered on 30 Aug 2012, 03:06 AM
So if you can't add an item in the change event of the dataSource, what is the best way to append/ prepend an item to a ComboBox after the data has been retrieved? It looks like there's an undocumented dataBound event, but that seems to yield the same result as the change event.
0
Nicklas
Top achievements
Rank 1
answered on 25 Aug 2013, 12:12 AM
I have the same issue...
tried dataBound event but hangs/loops as you say.
How can i add an item manually after loading from db/json?
0
Georgi Krustev
Telerik team
answered on 29 Aug 2013, 08:16 AM
Hello Nicklas,

 
When add item to the DataSource, "change" event is raised and thus the widget falls into infinitive loop. You can handle this with a privite variable. Check the updated jsFiddle demo.

Regards,
Georgi Krustev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Nicklas
Top achievements
Rank 1
answered on 09 Sep 2013, 12:04 AM
Thank you Georgi!
Your code works like a charm. Perfect!

Sincerely
Nicklas
Tags
ComboBox
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Georgi Krustev
Telerik team
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Cory Deppen
Top achievements
Rank 1
Nicklas
Top achievements
Rank 1
Share this question
or