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

Sort TreeList Nodes

1 Answer 16 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Veteran
Iron
Iron
Joel asked on 30 Mar 2020, 05:39 PM

My requirements say that I must sort the items in the treelist alphabetically.  This includes the child nodes.  This control uses a "flat hierarchy" because it is a table with parent references.  When I sort the source data alphabetically it doesn't seem to change anything.  I need to short by Group.Name:

<script id="icon-template" type="text/x-kendo-template">
    <div class='group-icon'
         style='background-image: url(@Url.Content("#: ImageUrl #"));'></div>
    <div class='group-name'>#: Name #</div>
</script>
 
@(Html.Kendo().TreeList<Group>()
    .Name("treelist")
    .Columns(columns =>
    {
        if (!Model.GetBoolValue(Glossary.Models.Group.Keys.IsHideDetails))
        {
            columns.Add().Command(c => { c.Custom().Text("Details").Name("detailButton").ClassName("detailButton").Click("goDetail"); }).Width(Glossary.Portal.ButtonWidth);
        }
 
        if (Model.GetBoolValue(Glossary.Models.Group.Keys.IsHideMeta))
        {
            columns.Add().Field(e => e.Name).TemplateId("icon-template").Width(225);
        }
        else
        {
            columns.Add().Field(e => e.Name).TemplateId("icon-template");
        }
    })
    .DataSource(dataSource => dataSource
        .ServerOperation(false)
        .Read(read => read.Action("IndexJson", "Groups").Data("getData"))
        .Model(m =>
        {
            m.Id(f => f.Id);
            m.ParentId(f => f.ParentId);
            m.Expanded(true);
            m.Field(f => f.Name);
        }).Events(events => events.Error("onError"))
      ).Events(evt => evt.DataBound("treeListBound"))
)

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Alex Hajigeorgieva
Telerik team
answered on 02 Apr 2020, 09:47 AM

Hello, Joel,

Have you tried adding a sort to the DataSource configuration?

 .DataSource(dataSource => dataSource
     .Sort(s=>s.Add(f=>f.Name))

I ran a quick test in the enclosed project and it works as expected.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
TreeList
Asked by
Joel
Top achievements
Rank 1
Veteran
Iron
Iron
Answers by
Alex Hajigeorgieva
Telerik team
Share this question
or