This is a migrated thread and some comments may be shown as answers.

ComboBox Grouping and SelectedIndex

1 Answer 266 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Monkey
Top achievements
Rank 1
Monkey asked on 05 Apr 2016, 02:02 PM

I've got a ComboBox which uses Grouping and I'm having trouble setting the selected item:

            @(Html.Kendo().ComboBox()
                  .Name("GroupedList")
                  .Placeholder("Select...")
                  .DataValueField("Value")
                  .DataTextField("Text")
                  .MinLength(3)
                  .Filter("contains")
                  .HtmlAttributes(new { style = "width:100%;" })
                  .Height(400)
                  .DataSource(source => source
                      .Custom()
                      .Group(g => g.Add("GroupKey", typeof(string)))
                      .Transport(transport => transport
                          .Read(read =>
                          {
                              read.Action("GetMyItems", "MyController");
                          })
                      )
                      .ServerFiltering(false)
                  )
            )

My controler is returning JSON in the following format with one of the items optionally having "Selected":true

[{"GroupKey":"Address","GroupName":"Address","Selected":false,"Text":"Correspondence Post Code","Value":"821"},...etc..]

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 07 Apr 2016, 10:36 AM
Hello Kevin,

The ComboBox will not pre-select an item that has a property Selected set to "true". Selecting an item can be done either by specified either by using the SelectedIndex() method (calling it with the index of the item you want to be selected, for example: SelectedIndex(3)) or by using the Value() method, to which you can pass the text of the item you want to select, for instance: Value("Item1").

Regards,
Ivan Danchev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Monkey
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or