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

add a new item and refresh dropdownlist

5 Answers 774 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 31 Oct 2013, 09:32 AM
Hello again,
How can i add a new item to the datasource of the dropdownlist, and after that do a refresh,so i can see the new added item.

Thanks and regards,
Daniel

5 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 31 Oct 2013, 02:40 PM
Hi Daniel,

To accomplish this please use the dataSource's add method. Once the item is added the DropDownList will automatically refresh.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Daniel
Top achievements
Rank 1
answered on 04 Nov 2013, 07:35 AM
kendo.data.dataSource is the source of a dropdownlist?
the ideea is that i added something using the serverside,the source has the new value,but the dropdown remains with the same elements.
and i used ajax on client side to call the fill for a dropdown.
0
Alexander Valchev
Telerik team
answered on 04 Nov 2013, 08:30 AM
Hello Daniel,

The data of an Ajax bound DropDownList is stored in its DataSource (instance of kendo.data.DataSource). You should obtain a reference to the DataSource via jQuery:
$("#dropDownListID").data("kendoDropDownList")
    .dataSource.add({"text": "new Item", "value": 1000});

Where dropDownListID is the ID of the DropDown element, text and value are respectively the dataTextField and the dataValueField of the widget.

In case you added a record in the data base and would like to fetch the new data from the server, you need to call the read method of the DataSource. Add method inserts new entry on the client.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Daniel
Top achievements
Rank 1
answered on 06 Nov 2013, 10:56 AM
the scenario is exactly the oposite.
I added a new item on server-side ,the source now it has its new item,and somehow i need to refresh the dropdownlist on the client,the .refresh or the .datasource.Read() does not do the trick.
or do you mean that what i still need is to call .Read() from the server? in that case how?

Regards,
Daniel
0
Alexander Valchev
Telerik team
answered on 06 Nov 2013, 12:58 PM
Hi Daniel,

I mean that you should call dataSource.read() (starting with a small letter) on the client side. The method will trigger the read transport of the DataSource which will issue  Ajax request to the server. When the new data is retrieved the DropDownList widget will refresh automatically.

In case you still have problems please provide the relevant code so we can check your current configuration.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
DropDownList
Asked by
Daniel
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or