I use KendoUI ComboBox and I want to put a default select item.
In KendoUI ComboBox I didn't find the way to put the default value in text and not with index.
<script>
$("#combobox").kendoComboBox({
dataSource: [
{ id: 1, name: "Apples" },
{ id: 2, name: "Oranges" }
],
dataTextField: "name",
dataValueField: "id"
});
var combobox = $("#combobox").data("kendoComboBox");
combobox.select(combobox.ul.children().eq(0));
</script>
Here is the example. How can convert it to put text?
As @SatyaRanjanSahoo says you should use
value
but you should use theid
value otherwise you will be forcing a value that might not be in the DataSource.Example, If you do:
this will show
Apricot
but this is not in theDataSource
meanwhile, if you do:This will show
Oranges
that is the correct value for the item whichid
is2
.So, unless you are sure that the value set in
value
call is a validdataTextField
I would recommend using thedataValueField
.Check this in the following code snippet...