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

Add a new item as First item after using DataSource...

1 Answer 647 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nicklas
Top achievements
Rank 1
Nicklas asked on 25 Aug 2013, 12:09 AM

Im using the following code to read from a database, output to json and transfer to my Kendo UI Combobox.
It works great. BUT i canĀ“t figure out how to do add a special item that is first in the list and is selectable.
I would like to add "No Project" and it should be selected as default. It should be on top of the list.

               var project = $("#project").kendoComboBox({
                        filter: "contains",
                        height: 300,
                        //text: "No Project",
                        //value: "",
                        autoBind: false,
                        suggest: true,
                        highLightFirst: false,
                        placeholder: "Select project...",
                        dataTextField: "DBText",
                        dataValueField: "DBValue",
                        template: '<span class=\"comboList\">${ data.DBText }</span>',
                        change: ProjectonChange,
                        dataSource: {
                            type: "json",
                            serverFiltering: false,
                           
                            transport: {
                                read: "ListCustomers.cshtml?list=project&uid=@QueryUserId"
                            }
                        }
                    }).data("kendoComboBox");

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 27 Aug 2013, 11:56 AM
Hello Nicklas,

You can add an item to the dataSource binded to the ComboBox and then select this item. But this can be done after the dataSource is populated with the remote data. Using autoBind = false, makes the widget bind its dataSource when it is opened or something is typed inside the text box, so you will need to add the item after the dataSource is binded.

Please check the following example showing a possible implementation:

http://jsbin.com/eQeD/2/edit
 
Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ComboBox
Asked by
Nicklas
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or