New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Loading and expanding only the first level data in the TreeList
Environment
Product | Telerik UI for ASP.NET MVC TreeList |
Progress Telerik UI for ASP.NET MVC version | Created 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 MVC TreeList.
Solution
To achieve the desired results:
- Set the TreeList
AutoBind()
property explicitly tofalse
. - Make a read request (the custom call which will return the initial data) by using the client-side dataSource's
read()
method. - Use the client-side TreeListDataSource's
load()
method to load the root. - 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 MVC TreeList Resources
See Also
- Client-Side API Reference of the TreeList for ASP.NET MVC
- Server-Side API Reference of the TreeList for ASP.NET MVC
- Server-Side TagHelper API Reference of the TreeList for ASP.NET MVC
- Telerik REPL: Load and expand only the first level data in the TreeList
- Telerik UI for ASP.NET MVC Breaking Changes
- Telerik UI for ASP.NET MVC Knowledge Base