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

Grouping using SelectListItems

1 Answer 60 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 09 Mar 2017, 11:06 PM

Is there any support for using SelectListItems as a datasource for ComboBoxes?

I would like to use it to do grouping, but I am unsure how to group where my datasource is a list of SelectListItems:

The following causes an error When I try to group on the Group's Name. Any other way of doing it?

<div class="demo-section k-content">
    <h4>Customers</h4>
 
    @(Html.Kendo().ComboBox()
          .Name("customers")
          .DataTextField("Text")
          .DataValueField("Value")
          .MinLength(3)
          .HtmlAttributes(new { style = "width:100%;" })
          .Height(400)
          .DataSource(source =>  source
              .Custom()
              .Group(g => g.Add("Group.Name", typeof(string)))
              .Transport(transport => transport
                .Read(read =>
                {
                    read.Action("Customers_Read", "ComboBox")
                        .Data("onAdditionalData");
                }))
              .ServerFiltering(true))
     )
</div>
<script>
    function onAdditionalData() {
        return {
            text: $("#customers").val()
        };
    }
</script>

1 Answer, 1 is accepted

Sort by
0
Accepted
Nencho
Telerik team
answered on 13 Mar 2017, 10:54 AM
Hello Alex,

I am afraid that the structure of the SelectListItems class does not fit to the scenario, where a grouping could be achieved with the ComboBox. In order to achieve the desired functionality, using SelectListItem, you should extend the class by adding the Name property.

public class MySelectListItem: SelectListItem
{
    public string Name { get; set; }
}

Then, you will be able to group by the Name property.

Regards,
Nencho
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Alex
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or