Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change selected value of kendo ui dropdownlist

I have a kendo ui dropdownlist in my view:

$("#Instrument").kendoDropDownList({     dataTextField: "symbol",     dataValueField: "symbol",     dataSource: data,     index: 0 }); 

How can I change the selected value of it using jQuery? I tried:

$("#Instrument").val(symbol); 

But it doesn't work as expected.

like image 243
anilca Avatar asked Apr 19 '13 14:04

anilca


People also ask

How to set selected value in kendo dropdown?

If your KendoDropdown has a change event, you must trigger it manually by calling dropdownlist. trigger("change"); after calling select .

How do you set values in kendo multiselect?

If you click on button the multi-value input gets: name1 , name2 and name6 . EDIT If you want to add to current selected values then do: $("#button"). on("click", function () { var selected = multiselect.

How do I select the first item in kendo Dropdownlist?

$("#CATEGORY_CODE"). data("kendoDropDownList"). select(0);


2 Answers

You have to use Kendo UI DropDownList select method (documentation in here).

Basically you should:

// get a reference to the dropdown list var dropdownlist = $("#Instrument").data("kendoDropDownList"); 

If you know the index you can use:

// selects by index dropdownlist.select(1); 

If not, use:

// selects item if its text is equal to "test" using predicate function dropdownlist.select(function(dataItem) {     return dataItem.symbol === "test"; }); 

JSFiddle example here

like image 111
OnaBai Avatar answered Sep 22 '22 06:09

OnaBai


The Simplest way to do this is:

$("#Instrument").data('kendoDropDownList').value("A value"); 

Here is the JSFiddle example.

like image 34
Gang Avatar answered Sep 24 '22 06:09

Gang