New to Telerik UI for ASP.NET CoreStart a free 30-day trial

Loading and expanding only the first level data in the TreeList

Environment

ProductTelerik UI for ASP.NET Core TreeList
Progress Telerik UI for ASP.NET Core versionCreated with the 2023.3.1010 version

Description

How do I expand only the first item on page load in the Telerik UI for ASP.NET Core TreeList.

Solution

To achieve the desired results:

  1. Set the TreeList AutoBind() property explicitly to false.
  2. Make a read request (the custom call which will return the initial data) by using the client-side dataSource's read() method.
  3. Use the client-side TreeListDataSource's load() method to load the root.
  4. To expand only the items which are in the view, use the client-side expand() method - this will not make a request for non-loaded items.
Index.cshtml
    @(Html.Kendo().TreeList<EmployeeDirectoryRemoteModel>()
        .Name("treelist")
        .Columns(columns =>
        {
            columns.Add().Field(f => f.FirstName).Width(250);
            columns.Add().Field(e => e.LastName);
            columns.Add().Field(e => e.Position);
            columns.Add().Field(e => e.Extension).Title("Ext").Format("{0:#}");
        })
        .AutoBind(false)
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("Index", "EmployeeDirectory"))
            .Model(m => {
                m.Id(f => f.EmployeeId);
                m.ParentId(f => f.ReportsTo);
                m.Field(f => f.FirstName);
                m.Field(f => f.LastName);
                m.Field(f => f.ReportsTo);
            })
        )
    )

More ASP.NET Core TreeList Resources

See Also