Example of DOM Virtualization in ASP.NET MVC Tree Grid Control
DOM virtualization is a performance optimization feature that renders only the visible rows within the Tree Grid viewport instead of rendering the entire dataset. This significantly improves performance when working with large volumes of hierarchical data.
@Html.UiTreeGrid(new UiTreeGridOptions
{
Id = "TreeGrid",
OnQueryCellInfo = "queryCellInfo",
DataUrl = Url.Action("DomVirtualizationRows", "TreeGridDemo"),
ServerOperations = false,
Height = "400px",
RowHeight = 50,
AllowSorting = true,
EnableVirtualization = true,
IdMapping = "ItemID",
ParentIdMapping = "ParentItemID",
TreeColumnIndex = 2,
AllowPaging = false,
Selection = UiGridSelection.Single,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "ItemID", HeaderText = "ID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right, IsPrimaryKey = true },
new UiGridColumn { Field = "ParentItemID", HeaderText = "Parent ID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right, Visible = false },
new UiGridColumn { Field = "ItemName", HeaderText = "Inventory Name" },
new UiGridColumn { Field = "ItemType", HeaderText = "Type", Visible = false },
new UiGridColumn { Field = "Category", HeaderText = "Category" },
new UiGridColumn { Field = "Region", HeaderText = "Location" },
new UiGridColumn { Field = "Supplier", HeaderText = "Supplier" },
new UiGridColumn { Field = "StockStatus", HeaderText = "Stock Status" },
new UiGridColumn { Field = "Quantity", HeaderText = "Quantity", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right, EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "UnitPrice", HeaderText = "Unit Price", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit }
}
})
<style>
.rg-badge {
box-sizing: border-box;
border-radius: 4px;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-weight: 500;
width: 120px;
min-height: 32px;
line-height: 1.2;
text-align: center;
}
.rg-badge-stock-available {
color: #15803d;
background-color: #fff;
border: 1.5px solid #ede3fb;
border-radius: 20px;
}
.rg-badge-stock-low {
color: #b45309;
background-color: #fff;
border: 1.5px solid #ede3fb;
border-radius: 20px;
}
.rg-badge-stock-out {
color: #dc2626;
background-color: #fff;
border: 1.5px solid #ede3fb;
border-radius: 20px;
}
.rg-badge-stock-discontinued {
color: #6b7280;
background-color: #fff;
border: 1.5px solid #ede3fb;
border-radius: 20px;
}
.rg-region {
display: flex;
gap: 10px;
align-items: center;
}
.rg-region-flag {
display: inline-flex;
width: 20px;
height: 14px;
border-radius: 2px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
background-size: contain;
background-repeat: no-repeat;
background-position: center;
flex-shrink: 0;
}
</style>
@Html.UiTreeGrid(new UiTreeGridOptions
{
Id = "TreeGrid",
OnQueryCellInfo = "queryCellInfo",
DataUrl = Url.Action("DomVirtualizationRows", "TreeGridDemo"),
ServerOperations = false,
Height = "400px",
RowHeight = 50,
AllowSorting = true,
EnableVirtualization = true,
IdMapping = "ItemID",
ParentIdMapping = "ParentItemID",
TreeColumnIndex = 2,
AllowPaging = false,
Selection = UiGridSelection.Single,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "ItemID", HeaderText = "ID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right, IsPrimaryKey = true },
new UiGridColumn { Field = "ParentItemID", HeaderText = "Parent ID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right, Visible = false },
new UiGridColumn { Field = "ItemName", HeaderText = "Inventory Name" },
new UiGridColumn { Field = "ItemType", HeaderText = "Type", Visible = false },
new UiGridColumn { Field = "Category", HeaderText = "Category" },
new UiGridColumn { Field = "Region", HeaderText = "Location" },
new UiGridColumn { Field = "Supplier", HeaderText = "Supplier" },
new UiGridColumn { Field = "StockStatus", HeaderText = "Stock Status" },
new UiGridColumn { Field = "Quantity", HeaderText = "Quantity", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right, EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "UnitPrice", HeaderText = "Unit Price", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit }
}
})
<script>
function getStatusClass(status) {
var normalized = (status || '').toLowerCase();
if (normalized.indexOf('discontinued') === 0) return 'rg-badge-stock-discontinued';
if (normalized.indexOf('low stock') === 0) return 'rg-badge-stock-low';
if (normalized.indexOf('out of stock') === 0) return 'rg-badge-stock-out';
return 'rg-badge-stock-available';
}
function getFlagSvg(region) {
var svg = '';
switch (region) {
case 'United States':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#B22234"/><rect y="0" width="20" height="2" fill="#fff"/><rect y="4" width="20" height="2" fill="#fff"/><rect y="8" width="20" height="2" fill="#fff"/><rect y="12" width="20" height="2" fill="#fff"/><rect width="8" height="8" fill="#3C3B6E"/></svg>';
break;
case 'Canada':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#fff"/><rect width="4" height="14" fill="#D52B1E"/><rect x="16" width="4" height="14" fill="#D52B1E"/><path d="M10 4 L11 6 L9.5 6.5 L11 7 L10 10 L9 7 L7.5 6.5 L9 6 Z" fill="#D52B1E"/></svg>';
break;
case 'United Kingdom':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#012169"/><path d="M0 0L20 14M20 0L0 14" stroke="#FFF" stroke-width="3"/><path d="M10 0V14M0 7H20" stroke="#FFF" stroke-width="4"/><path d="M10 0V14M0 7H20" stroke="#C8102E" stroke-width="2"/></svg>';
break;
case 'France':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="7" height="14" fill="#0055A4"/><rect x="7" width="6" height="14" fill="#FFF"/><rect x="13" width="7" height="14" fill="#EF4135"/></svg>';
break;
case 'Australia':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#012169"/><rect width="8" height="6" fill="#012169"/><path d="M0 0L8 6M8 0L0 6" stroke="#FFF" stroke-width="1"/><path d="M4 0V6M0 3H8" stroke="#FFF" stroke-width="2"/><circle cx="15" cy="10" r="1.2" fill="#FFF"/><circle cx="17" cy="7" r="0.8" fill="#FFF"/></svg>';
break;
case 'Japan':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#FFF"/><circle cx="10" cy="7" r="4" fill="#BC002D"/></svg>';
break;
case 'Germany':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="4.67" fill="#000"/><rect y="4.67" width="20" height="4.67" fill="#DD0000"/><rect y="9.34" width="20" height="4.66" fill="#FFCE00"/></svg>';
break;
case 'Singapore':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="7" fill="#EF3340"/><rect y="7" width="20" height="7" fill="#FFF"/><circle cx="6" cy="4" r="2.2" fill="#FFF"/><circle cx="7" cy="4" r="1.7" fill="#EF3340"/></svg>';
break;
case 'Brazil':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#009B3A"/><path d="M10 1 L19 7 L10 13 L1 7 Z" fill="#FEDF00"/><circle cx="10" cy="7" r="3.5" fill="#002776"/></svg>';
break;
case 'Netherlands':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="4.67" fill="#AE1C28"/><rect y="4.67" width="20" height="4.67" fill="#FFF"/><rect y="9.34" width="20" height="4.66" fill="#21468B"/></svg>';
break;
case 'South Korea':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#FFF"/><circle cx="10" cy="7" r="3.5" fill="#CD2E3A"/><path d="M7 5 L10 8 L13 5" stroke="#0047A0" stroke-width="1.2" fill="none"/><path d="M7 9 L10 6 L13 9" stroke="#0047A0" stroke-width="1.2" fill="none"/></svg>';
break;
case 'Switzerland':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#D52B1E"/><rect x="8" y="3" width="4" height="8" fill="#FFF"/><rect x="6" y="5" width="8" height="4" fill="#FFF"/></svg>';
break;
case 'Sweden':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="14" fill="#006AA7"/><rect x="6" width="3" height="14" fill="#FECC02"/><rect y="5" width="20" height="3" fill="#FECC02"/></svg>';
break;
case 'Italy':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="7" height="14" fill="#009246"/><rect x="7" width="6" height="14" fill="#FFF"/><rect x="13" width="7" height="14" fill="#CE2B37"/></svg>';
break;
case 'Spain':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="4.67" fill="#AA151B"/><rect y="4.67" width="20" height="4.67" fill="#F1BF00"/><rect y="9.34" width="20" height="4.66" fill="#AA151B"/></svg>';
break;
case 'India':
svg = '<svg width="20" height="14" viewBox="0 0 20 14" style="border-radius:2px;box-shadow:0 1px 3px rgba(0,0,0,0.2)"><rect width="20" height="4.67" fill="#FF9933"/><rect y="4.67" width="20" height="4.67" fill="#FFF"/><rect y="9.34" width="20" height="4.66" fill="#138808"/><circle cx="10" cy="7" r="1.6" fill="#000080"/></svg>';
break;
default:
svg = '<svg width="20" height="14" viewBox="0 0 20 14"><rect width="20" height="14" fill="#6b7280"/></svg>';
}
return svg;
}
// Syncfusion's templates: the status as a badge, and the location with the flag of its country.
function queryCellInfo(args) {
if (args.column === 'StockStatus') {
var badge = document.createElement('div');
badge.className = 'rg-badge ' + getStatusClass(args.data.StockStatus);
badge.textContent = args.data.StockStatus;
args.content = badge;
} else if (args.column === 'Region') {
var place = document.createElement('div');
place.className = 'rg-region';
var flag = document.createElement('span');
flag.className = 'rg-region-flag';
// the markup is the page's own (getFlagSvg), not the data's
var holder = document.createElement('template');
holder.innerHTML = getFlagSvg(args.data.Country);
flag.appendChild(holder.content);
var name = document.createElement('span');
name.className = 'rg-region-name';
name.textContent = args.data.Region;
place.appendChild(flag);
place.appendChild(name);
args.content = place;
}
}
</script>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
using Newtonsoft.Json;
namespace YourApp.Controllers
{
public class TreeGridController : Controller
{
// The page is Views/TreeGrid/DomVirtualization.cshtml; it draws what ViewData holds.
public ActionResult DomVirtualization()
{
return View();
}
public class DomVirtualizationData
{
public int ItemID { get; set; }
public int? ParentItemID { get; set; }
public string ItemName { get; set; }
public string ItemType { get; set; }
public string SKU { get; set; }
public string Category { get; set; }
public string Region { get; set; }
public string Country { get; set; }
public string Supplier { get; set; }
public string StockStatus { get; set; }
public int Quantity { get; set; }
public int ReservedQuantity { get; set; }
public int AvailableQuantity { get; set; }
public int ReorderLevel { get; set; }
public double? UnitPrice { get; set; }
public double InventoryValue { get; set; }
public int DailyOrders { get; set; }
public int MonthlyUnitsSold { get; set; }
public double FulfillmentRate { get; set; }
public string DemandProfile { get; set; }
public DateTime? LastRestocked { get; set; }
public DateTime? NextDeliveryDate { get; set; }
public int? StorageCapacity { get; set; }
private static string[] warehouseNames = new string[]
{
"Chicago Central Fulfillment Center",
"Dallas South Distribution Center",
"Newark East Coast Hub",
"Atlanta Regional Warehouse",
"Reno West Fulfillment Center",
"Seattle Pacific Hub",
"Columbus Midwest Distribution Center",
"Denver Mountain Warehouse",
"Phoenix Desert Logistics Center",
"Portland Northwest Terminal",
"Memphis River Valley Depot",
"Salt Lake City Intermountain Hub",
"Richmond Mid-Atlantic Warehouse",
"Kansas City Central Plains Center",
"Nashville Southeast Logistics",
"Detroit Great Lakes Facility",
"Houston Gulf Coast Terminal",
"Charlotte Southern Hub",
"Omaha Heartland Distribution",
"Tampa Bay Southeast Depot",
"Milwaukee North Central Warehouse",
"Louisville Derby City Logistics",
"San Antonio Alamo Distribution",
"Indianapolis Crossroads Hub",
"Oakland Bay Area Terminal",
"Raleigh Research Triangle Depot",
"Orlando Sunshine Warehouse",
"Hartford Northeast Logistics"
};
private static string[] warehouseRegions = new string[]
{
"United States", "Canada", "United Kingdom", "France", "Australia", "Japan", "Germany", "Singapore",
"Brazil", "Netherlands", "South Korea", "Switzerland", "Sweden", "Italy", "Spain", "India"
};
private static string[] productNames = new string[]
{
"Wireless Noise-Cancelling Headphones",
"Stainless Steel Water Bottle (750ml)",
"Adjustable Ergonomic Laptop Stand",
"USB-C 7-in-1 Fast Charging Hub",
"Memory Foam Travel Neck Pillow",
"Smart LED Desk Lamp with Dimmer",
"Compact Digital Air Fryer (3.5L)",
"Resistance Band Set (5-piece)",
"Waterproof Hiking Daypack (35L)",
"Ergonomic Mesh Office Chair",
"Portable Bluetooth Speaker (Waterproof)",
"Double-Wall Insulated Coffee Mug",
"Ultra-Slim Wireless Charging Pad",
"Electric Kettle with Temperature Control",
"Bamboo Laptop Desk Table",
"Yoga Mat with Alignment Lines (6mm)",
"Cordless Vacuum Cleaner (Handheld)",
"LED Ring Light for Video Conferencing",
"Collapsible Silicone Food Storage Set",
"Car Phone Mount (Dashboard/Air Vent)",
"Mechanical Keyboard (Wireless RGB)",
"Portable Power Bank (20000mAh)",
"Scented Soy Candle Collection (3-pack)",
"Electric Toothbrush with UV Sanitizer",
"Anti-Fatigue Kitchen Mat (Gel Core)",
"Laptop Privacy Screen Filter (14-inch)",
"Reusable Beeswax Food Wraps (Set of 6)",
"Smart Plug with Energy Monitoring",
"Stainless Steel Lunch Box (3-compartment)",
"Adjustable Standing Desk Converter",
"Home Security Camera (Indoor/Outdoor)",
"Compostable Trash Bags (30-pack)",
"Digital Kitchen Scale (Precision 0.1g)",
"Retractable USB-C Cable (1m/3ft)",
"Cold Brew Coffee Maker (1.5L)",
"Foam Roller for Muscle Recovery",
"Desk Organizer with Wireless Charger",
"Portable Espresso Maker (Manual)",
"LED Strip Lights with Remote (5m)",
"Fitness Tracker Watch (Heart Rate Monitor)",
"Glass Meal Prep Containers (Set of 5)",
"Electric Salt and Pepper Grinder Set",
"Laptop Backpack with USB Charging Port",
"Silicone Baking Mat Set (2-pack)",
"Pocket-sized Multitool (12-in-1)",
"Showerhead with Handheld Attachment",
"Desktop Whiteboard (Magnetic, 24x18)",
"Automatic Pet Feeder (Programmable)",
"Sustainable Bamboo Toilet Paper (24 rolls)",
"Car Windshield Sun Shade (Foldable)",
"Wall-Mounted Jewelry Organizer Cabinet",
"Stainless Steel French Press (1L)",
"Wireless Ergonomic Vertical Mouse",
"Tea Infuser Water Bottle (500ml)",
"Drawer Organizer Dividers (Set of 8)",
"Laptop Cooling Pad with Dual Fans",
"Rechargeable Hand Warmers (Pair)",
"Kitchen Knife Block Set (6-piece)",
"Waterproof Phone Pouch for Swimming",
"Portable Clothes Steamer (Handheld)",
"Smart Thermostat (WiFi Enabled)",
"Stainless Steel Straws (Set of 8)",
"Cordless Phone Stand with Charger",
"Adjustable Weight Bench (Foldable)",
"Magnetic Fridge Storage Organizers",
"Electric Wine Opener with Foil Cutter",
"Memory Card Reader (USB-C/MicroSD/SD)",
"Insulated Grocery Bag (Cold/Hot)",
"Desk Cable Management Tray (Under-desk)",
"Cast Iron Skillet (12-inch Pre-seasoned)",
"WiFi Range Extender (Mesh Compatible)",
"Pressure Cooker with Slow Cook Mode",
"Hanging Toiletry Bag (Travel Size)",
"Monitor Stand with Storage Drawer",
"Electric Griddle (Non-stick, 20-inch)",
"Personal Blender (600ml, Portable)",
"Adjustable Ankle Weights (2 x 2.5kg)",
"Smart Doorbell Camera (Battery Powered)",
"Silicone Spatula Set (Heat-resistant)",
"Laptop Sleeve with Handle (15.6-inch)",
"Humidifier with Essential Oil Tray",
"Self-Stick Wall Hooks (Set of 10)",
"Portable Jump Rope (Adjustable Length)",
"Vacuum Sealer Machine with Bags",
"Stainless Steel Colander (3 sizes)",
"USB Desk Fan with Silent Operation",
"Luggage Scale (Digital, Portable)",
"Bathroom Shelf Set (Corner, Rust-proof)",
"Electric Can Opener (One-touch)",
"Gaming Mouse Pad with LED Edge (Large)",
"Stackable Food Storage Jars (Set of 6)",
"Car Trunk Organizer (Collapsible)",
"Wall-mounted Key Holder with Shelf",
"Rice Cooker with Steamer Basket (5-cup)",
"Sleep Mask with Built-in Bluetooth",
"Pill Organizer (Weekly, 4-compartment)",
"Smart Air Purifier with HEPA Filter",
"Anti-Slip Yoga Towel (Microfiber)",
"Bike Phone Mount (Universal Fit)",
"Over-the-Door Towel Rack (No Drill)",
"Bread Maker Machine (2 lb Loaf)",
"Lid Organizer for Pots and Pans"
};
private static string[] categories = new string[]
{
"Consumer Electronics", "Home and Kitchen", "Office Supplies", "Travel Accessories",
"Fitness Equipment", "Audio and Entertainment", "Pet Supplies", "Automotive Accessories",
"Health and Personal Care", "Garden and Outdoor", "Baby and Kids", "Smart Home",
"Kitchen Appliances", "Sports Gear", "Storage and Organization"
};
private static string[] suppliers = new string[]
{
"Northstar Imports", "Blue Ridge Manufacturing", "Evergreen Consumer Goods",
"Summit Products", "Harbor Wholesale", "Pacific Rim Trading",
"Arrowhead Distributors", "Crestline Supply Co.", "Westbridge Logistics",
"Oakwood Merchandising", "Redwood Partners", "Silver Creek Enterprises",
"Ironclad Industrial", "Clearview Procurement", "Stonebridge Exports"
};
private static string[] demandProfiles = new string[]
{
"High Volume", "Steady", "Seasonal", "Low Volume",
"Peak Season Only", "Evergreen", "Rapid Growth", "Declining",
"New Product Launch", "Promotional Only"
};
private static Dictionary<string, string[]> countryCities = new Dictionary<string, string[]>()
{
{ "United States", new string[] { "New York", "Chicago", "Dallas", "Newark", "Atlanta", "Reno", "Seattle", "Columbus", "Denver", "Phoenix", "Portland", "Memphis", "Salt Lake City", "Richmond", "Kansas City", "Nashville", "Detroit", "Houston", "Charlotte", "Omaha", "Tampa", "Milwaukee", "Louisville", "San Antonio", "Indianapolis", "Oakland", "Raleigh", "Orlando", "Hartford" } },
{ "Canada", new string[] { "Toronto", "Montreal", "Vancouver", "Calgary", "Edmonton", "Ottawa", "Winnipeg", "Quebec City", "Hamilton", "Halifax", "London", "Mississauga", "Surrey", "Burnaby", "Laval", "Saskatoon", "Regina", "St. John's", "Kitchener", "Victoria", "Barrie", "Oshawa", "Gatineau", "Windsor", "Sudbury", "Brampton", "Markham", "Vaughan", "Richmond Hill", "Oakville", "Burlington", "St. Catharines", "Thunder Bay", "Kelowna", "Moncton" } },
{ "United Kingdom", new string[] { "London", "Birmingham", "Manchester", "Liverpool", "Leeds", "Glasgow", "Edinburgh", "Bristol", "Sheffield", "Newcastle", "Nottingham", "Leicester", "Cardiff", "Belfast", "Southampton", "Portsmouth", "Oxford", "Cambridge", "Brighton", "York" } },
{ "France", new string[] { "Paris", "Marseille", "Lyon", "Toulouse", "Nice", "Nantes", "Strasbourg", "Montpellier", "Bordeaux", "Lille", "Rennes", "Reims", "Le Havre", "Toulon", "Grenoble", "Dijon", "Angers", "Nimes", "Clermont-Ferrand" } },
{ "Australia", new string[] { "Sydney", "Melbourne", "Brisbane", "Perth", "Adelaide", "Gold Coast", "Canberra", "Newcastle", "Wollongong", "Hobart", "Darwin", "Cairns", "Geelong", "Townsville", "Launceston", "Toowoomba" } },
{ "Japan", new string[] { "Tokyo", "Osaka", "Kyoto", "Yokohama", "Nagoya", "Sapporo", "Fukuoka", "Kobe", "Kawasaki", "Hiroshima", "Sendai", "Kitakyushu", "Chiba", "Saitama", "Shizuoka", "Kumamoto" } },
{ "Germany", new string[] { "Berlin", "Hamburg", "Munich", "Cologne", "Frankfurt", "Stuttgart", "Dusseldorf", "Leipzig", "Dortmund", "Essen", "Bremen", "Dresden", "Hanover", "Nuremberg", "Duisburg", "Bochum" } },
{ "Singapore", new string[] { "Singapore Central", "Woodlands", "Tampines", "Jurong East", "Bedok", "Punggol", "Sengkang", "Ang Mo Kio", "Bukit Merah", "Clementi", "Toa Payoh", "Yishun", "Changi", "Marina Bay", "Orchard", "Novena" } },
{ "Brazil", new string[] { "Sao Paulo", "Rio de Janeiro", "Brasilia", "Salvador", "Fortaleza", "Belo Horizonte", "Manaus", "Curitiba", "Recife", "Porto Alegre", "Belem", "Goiania", "Campinas", "Florianopolis", "Natal", "Vitoria" } },
{ "Netherlands", new string[] { "Amsterdam", "Rotterdam", "The Hague", "Utrecht", "Eindhoven", "Groningen", "Tilburg", "Almere", "Breda", "Nijmegen", "Haarlem", "Arnhem", "Leiden", "Maastricht", "Zwolle", "Delft" } },
{ "South Korea", new string[] { "Seoul", "Busan", "Incheon", "Daegu", "Daejeon", "Gwangju", "Suwon", "Ulsan", "Changwon", "Goyang", "Yongin", "Seongnam", "Jeonju", "Cheongju", "Pohang", "Jeju City" } },
{ "Switzerland", new string[] { "Zurich", "Geneva", "Basel", "Lausanne", "Bern", "Winterthur", "Lucerne", "St. Gallen", "Lugano", "Biel", "Thun", "Fribourg", "Neuchatel", "Zug", "Schaffhausen", "Sion" } },
{ "Sweden", new string[] { "Stockholm", "Gothenburg", "Malmo", "Uppsala", "Vasteras", "Orebro", "Linkoping", "Helsingborg", "Jonkoping", "Norrkoping", "Lund", "Umea", "Gavle", "Boras", "Sodertalje", "Eskilstuna" } },
{ "Italy", new string[] { "Rome", "Milan", "Naples", "Turin", "Palermo", "Genoa", "Bologna", "Florence", "Venice", "Verona", "Bari", "Catania", "Padua", "Trieste", "Brescia", "Parma" } },
{ "Spain", new string[] { "Madrid", "Barcelona", "Valencia", "Seville", "Zaragoza", "Malaga", "Murcia", "Palma", "Las Palmas", "Bilbao", "Alicante", "Cordoba", "Valladolid", "Vigo", "Gijon", "Granada" } },
{ "India", new string[] { "Mumbai", "Delhi", "Bengaluru", "Hyderabad", "Chennai", "Kolkata", "Pune", "Ahmedabad", "Jaipur", "Surat", "Lucknow", "Kanpur", "Nagpur", "Indore", "Thane", "Bhopal", "Visakhapatnam", "Patna", "Vadodara", "Ghaziabad" } }
};
public static List<DomVirtualizationData> GetDomVirtualizationData()
{
List<DomVirtualizationData> data = new List<DomVirtualizationData>();
var random = new Random(42);
int recordId = 10000;
for (int warehouseIndex = 1; warehouseIndex <= 25000; warehouseIndex++)
{
int warehouseId = ++recordId;
int regionIndex = (warehouseIndex - 1) % warehouseRegions.Length;
var childRecords = new List<DomVirtualizationData>();
int warehouseQuantity = 0;
int warehouseReserved = 0;
int warehouseAvailable = 0;
double warehouseInventoryValue = 0;
int availableCount = 0;
int lowStockCount = 0;
int outOfStockCount = 0;
int discontinuedCount = 0;
for (int itemIndex = 1; itemIndex <= 3; itemIndex++)
{
int itemId = ++recordId;
string region = warehouseRegions[regionIndex];
int categoryIndex = random.Next(categories.Length);
int supplierIndex = random.Next(suppliers.Length);
string[] cities = countryCities[region];
string childRegion = cities[(warehouseIndex + itemIndex) % cities.Length];
string childItemName = childRegion + " Facility";
int monthlyUnitsSold = 200 + ((warehouseIndex * (itemIndex + 9)) % 2500);
double unitPrice = 15 + ((warehouseIndex * itemIndex * 13) % 250);
int quantity = 100 + ((warehouseIndex * itemIndex * 29) % 3000);
int reservedQuantity = 0;
int availableQuantity = 0;
int reorderLevel = 0;
string stockStatus = "";
int statusSeed = (warehouseIndex + itemIndex) % 20;
if (statusSeed == 0)
{
stockStatus = "Out of Stock";
quantity = 0;
reservedQuantity = 0;
availableQuantity = 0;
reorderLevel = 100;
outOfStockCount++;
}
else if (statusSeed <= 3)
{
stockStatus = "Low Stock";
availableQuantity = Math.Max(10, (int)Math.Floor(quantity * 0.10));
reservedQuantity = quantity - availableQuantity;
reorderLevel = availableQuantity + 150;
lowStockCount++;
}
else if (statusSeed == 4)
{
stockStatus = "Discontinued";
availableQuantity = (int)Math.Floor(quantity * 0.30);
reservedQuantity = 0;
reorderLevel = 0;
discontinuedCount++;
}
else
{
stockStatus = "Available";
reservedQuantity = (int)Math.Floor(quantity * 0.15);
availableQuantity = quantity - reservedQuantity;
reorderLevel = (int)Math.Floor(quantity * 0.25);
availableCount++;
}
warehouseQuantity += quantity;
warehouseReserved += reservedQuantity;
warehouseAvailable += availableQuantity;
warehouseInventoryValue += quantity * unitPrice;
childRecords.Add(new DomVirtualizationData()
{
ItemID = itemId,
ParentItemID = warehouseId,
ItemName = childItemName,
ItemType = "Product",
SKU = "SKU-" + warehouseIndex.ToString("D5") + "-" + itemIndex.ToString("D2"),
Category = categories[categoryIndex],
Region = childRegion,
Country = region,
Supplier = suppliers[supplierIndex],
StockStatus = stockStatus,
Quantity = quantity,
ReservedQuantity = reservedQuantity,
AvailableQuantity = availableQuantity,
ReorderLevel = reorderLevel,
UnitPrice = unitPrice,
InventoryValue = quantity * unitPrice,
DailyOrders = (int)Math.Ceiling(monthlyUnitsSold / 30.0),
MonthlyUnitsSold = monthlyUnitsSold,
FulfillmentRate = 93 + ((warehouseIndex + itemIndex) % 7),
DemandProfile = demandProfiles[(warehouseIndex + itemIndex) % demandProfiles.Length],
LastRestocked = new DateTime(2025, ((warehouseIndex + itemIndex) % 12) + 1, ((warehouseIndex + itemIndex * 2) % 27) + 1),
NextDeliveryDate = new DateTime(2025, ((warehouseIndex + itemIndex + 1) % 12) + 1, ((warehouseIndex + itemIndex * 4) % 27) + 1)
});
}
string warehouseStatus = "Available";
if (discontinuedCount == childRecords.Count)
{
warehouseStatus = "Discontinued";
}
else if (outOfStockCount == childRecords.Count)
{
warehouseStatus = "Out of Stock";
}
else if (lowStockCount > 0 || outOfStockCount > 0)
{
warehouseStatus = "Low Stock";
}
data.Add(new DomVirtualizationData()
{
ItemID = warehouseId,
ParentItemID = null,
ItemName = warehouseNames[regionIndex] + " " + ((warehouseIndex - 1) / warehouseNames.Length + 1),
ItemType = "Warehouse",
Category = "Multi-category inventory",
Region = warehouseRegions[regionIndex],
Country = warehouseRegions[regionIndex],
Supplier = "Regional supplier network",
StockStatus = warehouseStatus,
Quantity = warehouseQuantity,
ReservedQuantity = warehouseReserved,
AvailableQuantity = warehouseAvailable,
ReorderLevel = (int)Math.Floor(warehouseQuantity * 0.20),
UnitPrice = null,
InventoryValue = warehouseInventoryValue,
DailyOrders = 500 + ((warehouseIndex * 23) % 2500),
MonthlyUnitsSold = 15000 + ((warehouseIndex * 97) % 55000),
FulfillmentRate = 95 + ((warehouseIndex % 10) / 10.0),
DemandProfile = demandProfiles[warehouseIndex % demandProfiles.Length],
StorageCapacity = warehouseQuantity + (int)Math.Floor(warehouseQuantity * 0.25),
LastRestocked = new DateTime(2025, ((warehouseIndex + 2) % 12) + 1, ((warehouseIndex * 3) % 27) + 1)
});
data.AddRange(childRecords);
}
return data;
}
}
private static string domVirtualizationJson;
/// <summary>The 100,000 inventory rows as JSON (the DOM virtualization sample's DataUrl): made once, sent as one array. They are not in the page, which would be 90 MB.</summary>
[HttpPost]
[ValidateJsonAntiForgeryToken]
public ActionResult DomVirtualizationRows()
{
if (domVirtualizationJson == null)
{
domVirtualizationJson = Newtonsoft.Json.JsonConvert.SerializeObject(DomVirtualizationData.GetDomVirtualizationData());
}
return Content(domVirtualizationJson, "application/json");
}
}
}
@* 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>
@* Tree Grids with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
With DOM virtualization enabled, the Tree Grid calculates the content height and renders only the necessary tr elements for the visible portion of the control. As the user scrolls, previously rendered rows are replaced with newly required rows, ensuring that only a minimal number of DOM elements are maintained at any time. This improves rendering speed and memory usage for large datasets.
DOM virtualization is enabled by setting the enableDomVirtualization property to true. This demo loads 100,000 hierarchical records using DOM virtualization. Row virtualization is enabled using the enableVirtualization property.