How do I sort the .DataSource when using DropDownListFor

3 posts, 0 answers
  1. Morten
    Morten avatar
    267 posts
    Member since:
    Jul 2012

    Posted 18 Aug 2015 Link to this post

    I build and bind a DropDownList as listed below.

    The "GetItemCategories" returns data I would like to sort before displayed in the DropDownList.

    How do I do the sorting?

     
    @(Html.Kendo().DropDownListFor(m => m.Category)
        .Name("Category")
        .DataTextField("Name")
        .DataValueField("Value")
        .HtmlAttributes(new { style = "width: 280px;" })
        .DataSource(source =>
        {
            source.Read(read =>
            {
                read.Action("GetItemCategories", "Helper");
            });
        })
        .Value(Model.ActionTimeFrameId.ToString())
    )

     

     

     

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Aug 2015 Link to this post

    Hello Morten,

    Please use custom transport as shown below: 

    @(Html.Kendo().DropDownList()
             .Name("products")
             .HtmlAttributes(new { style = "width: 250px" })
             .DataTextField("ProductName")
             .DataValueField("ProductID")
             .DataSource(source =>  source
                   .Custom()
                   .Sort(s => s.Add("ProductName"))
                   .Transport(tr => tr
                       .Read(read =>
                       {
                           read.Action("GetProducts", "Home");
                       })))
            )

     

    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Morten
    Morten avatar
    267 posts
    Member since:
    Jul 2012

    Posted 20 Aug 2015 in reply to Boyan Dimitrov Link to this post

    thanks a lot
Back to Top