I have a kendo UI multiselect input. I am populating the values with a JSON object. I want the first value to be selected. Based on the documenation I have given as below but the value is still not selected.
$("#days").kendoMultiSelect({
dataTextField: "text",
dataValueField: "value",
dataSource: days,
filter: "contains",
value: [
{ text: "First", value: "1" },
]
});
var days = [
{ text: "First", value: "1" },
{ text: "Second", value: "2" },
{ text: "Third", value: "3" },
{ text: "Fourth", value: "4" },
{ text: "Fifth", value: "5" }
];
The DropDownList enables you to configure its default item. The defaultItem property type has to match the data type. For example, if the data property contains a list of objects, the defaultItem has to be defined as an object with the same textField and valueField as the data items.
Because you have configured the dataValueField: "value"
in the value
array you need to provide the value
property values of the days objects.
So you just need to write value: [ "1" ]
:
$("#days").kendoMultiSelect({
dataTextField: "text",
dataValueField: "value",
dataSource: days,
filter: "contains",
value: [ "1" ]
});
Demo JSFiddle.
In case you are using server side binding, you can do this...
@(Html.Kendo().MultiSelect()
.Name("RolesVisibleToMultiSelect")
.Placeholder("Select Roles...")
.DataValueField("RoleId")
.DataTextField("RoleName")
.BindTo(Model.RequestDiscussion.RolesVisibleTo)
.Value(Model.RequestDiscussion.RolesVisibleTo.Select(r => r.RoleId).ToArray()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With