Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting default values in KENDO UI Multiselect

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" }

            ];
like image 300
ckv Avatar asked Jul 27 '13 05:07

ckv


People also ask

How do I set the default value of kendo DropDownList?

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.


2 Answers

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.

like image 104
nemesv Avatar answered Sep 18 '22 00:09

nemesv


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()))
like image 20
LawMan Avatar answered Sep 20 '22 00:09

LawMan