Example of Infinite Scrolling in ASP.NET MVC Tree Grid Control
This sample demonstrates the Tree Grid component with the infinite scrolling feature.
@* The editor's settings are in the view; the data they read (ViewData) is set in the controller action (see the controller tab). *@
@Html.UiTreeGrid(new UiTreeGridOptions
{
Id = "DefaultFunctionalities",
Data = ViewData["datasource"],
Height = "400px",
ChildMapping = "Children",
TreeColumnIndex = 1,
EnableInfiniteScrolling = true,
PageSize = 50,
Selection = UiGridSelection.Single,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "TaskID", HeaderText = "Player Jersey", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD1", HeaderText = "Player Name" },
new UiGridColumn { Field = "FIELD2", HeaderText = "Year", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD3", HeaderText = "Stint", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD4", HeaderText = "TMID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD5", HeaderText = "LGID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD6", HeaderText = "GS", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD7", HeaderText = "GP", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right }
}
})
@Html.UiTreeGrid(new UiTreeGridOptions
{
Id = "DefaultFunctionalities",
Data = ViewData["datasource"],
Height = "400px",
ChildMapping = "Children",
TreeColumnIndex = 1,
EnableInfiniteScrolling = true,
PageSize = 50,
Selection = UiGridSelection.Single,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "TaskID", HeaderText = "Player Jersey", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD1", HeaderText = "Player Name" },
new UiGridColumn { Field = "FIELD2", HeaderText = "Year", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD3", HeaderText = "Stint", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD4", HeaderText = "TMID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD5", HeaderText = "LGID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD6", HeaderText = "GS", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "FIELD7", HeaderText = "GP", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right }
}
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TreeGridController : Controller
{
// The page is Views/TreeGrid/InfiniteScrolling.cshtml; it draws what ViewData holds.
public ActionResult InfiniteScrolling()
{
ViewData["datasource"] = VirtualDataFormat.GetVirtualData();
return View();
}
public class VirtualDataFormat
{
public int TaskID { get; set; }
public string FIELD1 { get; set; }
public int FIELD2 { get; set; }
public int FIELD3 { get; set; }
public int FIELD4 { get; set; }
public int FIELD5 { get; set; }
public int FIELD6 { get; set; }
public int FIELD7 { get; set; }
public List<VirtualDataFormat> Children { get; set; }
public static List<VirtualDataFormat> GetVirtualData()
{
string[] Names = new string[] { "VINET", "TOMSP", "HANAR", "VICTE", "SUPRD", "HANAR", "CHOPS", "RICSU", "WELLI", "HILAA", "ERNSH", "CENTC",
"OTTIK", "QUEDE", "RATTC", "ERNSH", "FOLKO", "BLONP", "WARTH", "FRANK", "GROSR", "WHITC", "WARTH", "SPLIR", "RATTC", "QUICK", "VINET",
"MAGAA", "TORTU", "MORGK", "BERGS", "LEHMS", "BERGS", "ROMEY", "ROMEY", "LILAS", "LEHMS", "QUICK", "QUICK", "RICAR", "REGGC", "BSBEV",
"COMMI", "QUEDE", "TRADH", "TORTU", "RATTC", "VINET", "LILAS", "BLONP", "HUNGO", "RICAR", "MAGAA", "WANDK", "SUPRD", "GODOS", "TORTU",
"OLDWO", "ROMEY", "LONEP", "ANATR", "HUNGO", "THEBI", "DUMON", "WANDK", "QUICK", "RATTC", "ISLAT", "RATTC", "LONEP", "ISLAT", "TORTU",
"WARTH", "ISLAT", "PERIC", "KOENE", "SAVEA", "KOENE", "BOLID", "FOLKO", "FURIB", "SPLIR", "LILAS", "BONAP", "MEREP", "WARTH", "VICTE",
"HUNGO", "PRINI", "FRANK", "OLDWO", "MEREP", "BONAP", "SIMOB", "FRANK", "LEHMS", "WHITC", "QUICK", "RATTC", "FAMIA" };
List<VirtualDataFormat> DataCollection = new List<VirtualDataFormat>();
List<VirtualDataFormat> ChildCollection = new List<VirtualDataFormat>();
var rand = new Random();
var j = 1;
for (var i = 0; i <= 1000; i = j)
{
var name = (i % 100);
VirtualDataFormat Parent = new VirtualDataFormat()
{
TaskID = i + 1,
FIELD1 = Names[name],
FIELD2 = (i % 2 == 0) ? 1967 + 2 : (i % 5 == 0) ? 1967 + 8 : 1967 + 12,
FIELD3 = (i % 2 == 0) ? 395 + 2 : (i % 5 == 0) ? 395 + 1 : 395 + 25,
FIELD4 = (i % 2 == 0) ? 87 + 2 : (i % 5 == 0) ? 87 + 1 : 87 + 15,
FIELD5 = (i % 2 == 0) ? 410 + 2 : (i % 5 == 0) ? 410 + 1 : 410 + 45,
FIELD6 = (i % 2 == 0) ? 67 + 2 : (i % 5 == 0) ? 67 + 1 : 67 + 6,
FIELD7 = (i % 2 == 0) ? 35 + 2 : (i % 5 == 0) ? 24 + 1 : 45 + 12,
Children = new List<VirtualDataFormat>()
};
for ( j = i + 1; j < i + 6; j++)
{
var childName = ((i +j) % 100);
Parent.Children.Add(new VirtualDataFormat()
{
TaskID = j + 1,
FIELD1 = Names[childName],
FIELD2 = (j % 3 == 0) ? 1967 + (j + 2) : (j % 4 == 0) ? 1967 + (j + 1) : 1967 + j,
FIELD3 = (j % 3 == 0) ? 395 + (j + 2) : (j % 4 == 0) ? 395 + (j + 4) : 395 + (j + 13),
FIELD4 = (j % 3 == 0) ? 87 + (j + 2) : (j % 4 == 0) ? 87 + (j + 1) : 87 + (j + 12),
FIELD5 = (j % 3 == 0) ? 410 + (j + 2) : (j % 4 == 0) ? 410 + (j + 1) : 410 + (j + 14),
FIELD6 = (j % 3 == 0) ? 67 + (j + 2) : (j % 4 == 0) ? 67 + (j + 1) : 67 + (j + 7),
FIELD7 = (j % 3 == 0) ? 89 + (j + 2) : (j % 4 == 0) ? 94 + (j + 1) : 23 + (j + 7),
});
}
DataCollection.Add(Parent);
}
return DataCollection;
}
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Tree Grid Infinite scrolling, allows you to load data in lazy loading concept, which means the buffer data is loaded only when the scrollbar reaches the end of the scroller. To enable Infinite scrolling, set EnableInfiniteScrolling property as true.
Note: The Height property must be defined when enabling EnableInfiniteScrolling.