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.
It's possible to "natively" select by value:
Seems there's an easier way, at least in Kendo UI v2015.2.624:
If there's not a match in the dropdown, Kendo appears to set the dropdown to an unselected value, which makes sense.
I couldn't get @Gang's answer to work, but if you swap his
value
withsearch
, as above, we're golden.You have to use Kendo UI DropDownList
select
method (documentation in here).Basically you should:
If you know the index you can use:
If not, use:
JSFiddle example here
Since this is one of the top search results for questions related to this I felt it was worth mentioning how you can make this work with Kendo().DropDownListFor() as well.
Everything is the same as with OnaBai's post except for how you select the item based off of its text and your selector.
To do that you would swap out dataItem.symbol for dataItem.[DataTextFieldName]. Whatever model field you used for .DataTextField() is what you will be comparing against.
The Simplest way to do this is:
Here is the JSFiddle example.