Example of Virtual Scrolling in ASP.NET Core Data Grid Control
This sample highlights row and column virtualization in the Grid component, allowing efficient rendering and smooth scrolling of large datasets with excellent performance, along with full CRUD support and column templates.
@Html.UiGrid(new UiGridOptions
{
Id = "VirtualGrid",
Data = new List<object>(),
OnQueryCellInfo = "queryCellInfo",
OnDataLoaded = "hide",
EnableColumnVirtualization = true,
EnableVirtualization = true,
RowHeight = 50,
Height = "400px",
EditSettings = new UiEditSettings { AllowAdding = true, AllowEditing = true, AllowDeleting = true, Mode = UiEditMode.Normal },
Toolbar = new List<string> { "Add", "Edit", "Delete", "Update", "Cancel" },
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "OrderID", HeaderText = "Order ID", Width = 110, IsPrimaryKey = true, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "OrderDate", HeaderText = "Order Date", Type = UiColumnType.Date, Width = 140, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy", EditType = UiEditType.DatePickerEdit },
new UiGridColumn { Field = "ShipDate", HeaderText = "Ship Date", Type = UiColumnType.Date, Width = 140, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy", EditType = UiEditType.DatePickerEdit },
new UiGridColumn { Field = "OrderStatus", HeaderText = "Order Status", Width = 140, TextAlign = UiTextAlign.Center, EditType = UiEditType.DropDownEdit, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "Priority", HeaderText = "Priority", Width = 120, TextAlign = UiTextAlign.Center, EditType = UiEditType.DropDownEdit, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "CustomerName", HeaderText = "Customer Name", Width = 190, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "CustomerID", HeaderText = "Customer ID", Width = 110, Visible = false },
new UiGridColumn { Field = "Email", HeaderText = "Email", Width = 200 },
new UiGridColumn { Field = "Phone", HeaderText = "Phone Number", Width = 140, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "ShipAddress", HeaderText = "Ship Address", Width = 180 },
new UiGridColumn { Field = "ShipCity", HeaderText = "Ship City", Width = 120 },
new UiGridColumn { Field = "ShipState", HeaderText = "Ship State Code", Width = 130 },
new UiGridColumn { Field = "ShipPostalCode", HeaderText = "Ship Postal Code", Width = 130, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "ShipCountry", HeaderText = "Ship Country", Width = 150 },
new UiGridColumn { Field = "ProductName", HeaderText = "Product Name", Width = 250 },
new UiGridColumn { Field = "ProductID", HeaderText = "Product ID", Width = 110, Visible = false },
new UiGridColumn { Field = "Category", HeaderText = "Category", Width = 120 },
new UiGridColumn { Field = "Warehouse", HeaderText = "Ware house", Width = 110, Visible = false, EditType = UiEditType.DropDownEdit },
new UiGridColumn { Field = "InventoryCount", HeaderText = "Inventory Count", Width = 150, TextAlign = UiTextAlign.Right, Visible = false },
new UiGridColumn { Field = "Quantity", HeaderText = "Quantity", Type = UiColumnType.Number, Width = 100, TextAlign = UiTextAlign.Right, EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "UnitPrice", HeaderText = "Unit Price", Type = UiColumnType.Number, Width = 110, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "Discount", HeaderText = "Discount (%)", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "Tax", HeaderText = "Tax (%)", Type = UiColumnType.Number, Width = 100, TextAlign = UiTextAlign.Right, EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "SubTotal", HeaderText = "Sub Total", Type = UiColumnType.Number, Width = 110, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "TaxAmount", HeaderText = "Tax Amount", Type = UiColumnType.Number, Width = 110, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "ShipFee", HeaderText = "Ship Fee", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "TotalAmount", HeaderText = "Total Amount", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "PaymentMethod", HeaderText = "Payment Method", Width = 140, EditType = UiEditType.DropDownEdit, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "PaymentStatus", HeaderText = "Payment Status", Width = 140, TextAlign = UiTextAlign.Center, EditType = UiEditType.DropDownEdit, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "Rating", HeaderText = "Delivery Rating", Width = 160, TextAlign = UiTextAlign.Center, Visible = false, EditType = UiEditType.DropDownEdit }
}
})
<style>
.virtual-statustemp { display: inline-block; min-width: 80px; padding: 2px 8px; border-radius: 4px; text-align: center; }
.virtual-statustemp.e-highcolor { background-color: #f8d7da; }
.virtual-statustemp.e-lowcolor { background-color: #d4edda; }
.virtual-statustemp.e-mediumcolor { background-color: #fff3cd; }
.virtual-statustemp.e-criticalcolor { background-color: #efacac; }
.virtual-statustemp.e-paidcolor { background-color: #e6f4ea; }
.virtual-statustemp.e-pendingcolor { background-color: #fff8e1; }
.virtual-statustemp.e-refundcolor { background-color: #fff0f0; }
.virtual-statustemp.e-deliveredcolor { background-color: #e6f3ea; }
.virtual-statustemp.e-shippedcolor { background-color: #e7f0fb; }
.virtual-statustemp.e-processingcolor { background-color: #fff8e6; }
.virtual-statustemp.e-packedcolor { background-color: #fff7ed; }
.virtual-statustemp.e-returnedcolor { background-color: #FCE4E4; }
.virtual-statustemp.e-cancelcolor { background-color: #f2f2f2; }
.virtual-statustemp.e-orderedcolor { background-color: #E0F2F1; }
.virtual-statustemp.e-failedcolor { background-color: #f2f2f2; }
.virtual-statustxt.e-highcolor { color: #b21f2d; }
.virtual-statustxt.e-lowcolor { color: #155724; }
.virtual-statustxt.e-mediumcolor { color: #856404; }
.virtual-statustxt.e-criticalcolor { color: darkred; }
.rating-stars { color: #e8a317; letter-spacing: 1px; white-space: nowrap; }
.rating-stars .off { color: #cfcfcf; }
#popup { display: none; margin-left: 8px; }
</style>
<div style="padding: 10px"><button type="button" id="generate">Load 100K Data</button><span id="popup" role="status">Loading...</span> <span id="performanceTime"></span></div>
@Html.UiGrid(new UiGridOptions
{
Id = "VirtualGrid",
Data = new List<object>(),
OnQueryCellInfo = "queryCellInfo",
OnDataLoaded = "hide",
EnableColumnVirtualization = true,
EnableVirtualization = true,
RowHeight = 50,
Height = "400px",
EditSettings = new UiEditSettings { AllowAdding = true, AllowEditing = true, AllowDeleting = true, Mode = UiEditMode.Normal },
Toolbar = new List<string> { "Add", "Edit", "Delete", "Update", "Cancel" },
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "OrderID", HeaderText = "Order ID", Width = 110, IsPrimaryKey = true, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "OrderDate", HeaderText = "Order Date", Type = UiColumnType.Date, Width = 140, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy", EditType = UiEditType.DatePickerEdit },
new UiGridColumn { Field = "ShipDate", HeaderText = "Ship Date", Type = UiColumnType.Date, Width = 140, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy", EditType = UiEditType.DatePickerEdit },
new UiGridColumn { Field = "OrderStatus", HeaderText = "Order Status", Width = 140, TextAlign = UiTextAlign.Center, EditType = UiEditType.DropDownEdit, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "Priority", HeaderText = "Priority", Width = 120, TextAlign = UiTextAlign.Center, EditType = UiEditType.DropDownEdit, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "CustomerName", HeaderText = "Customer Name", Width = 190, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "CustomerID", HeaderText = "Customer ID", Width = 110, Visible = false },
new UiGridColumn { Field = "Email", HeaderText = "Email", Width = 200 },
new UiGridColumn { Field = "Phone", HeaderText = "Phone Number", Width = 140, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "ShipAddress", HeaderText = "Ship Address", Width = 180 },
new UiGridColumn { Field = "ShipCity", HeaderText = "Ship City", Width = 120 },
new UiGridColumn { Field = "ShipState", HeaderText = "Ship State Code", Width = 130 },
new UiGridColumn { Field = "ShipPostalCode", HeaderText = "Ship Postal Code", Width = 130, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "ShipCountry", HeaderText = "Ship Country", Width = 150 },
new UiGridColumn { Field = "ProductName", HeaderText = "Product Name", Width = 250 },
new UiGridColumn { Field = "ProductID", HeaderText = "Product ID", Width = 110, Visible = false },
new UiGridColumn { Field = "Category", HeaderText = "Category", Width = 120 },
new UiGridColumn { Field = "Warehouse", HeaderText = "Ware house", Width = 110, Visible = false, EditType = UiEditType.DropDownEdit },
new UiGridColumn { Field = "InventoryCount", HeaderText = "Inventory Count", Width = 150, TextAlign = UiTextAlign.Right, Visible = false },
new UiGridColumn { Field = "Quantity", HeaderText = "Quantity", Type = UiColumnType.Number, Width = 100, TextAlign = UiTextAlign.Right, EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "UnitPrice", HeaderText = "Unit Price", Type = UiColumnType.Number, Width = 110, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "Discount", HeaderText = "Discount (%)", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "Tax", HeaderText = "Tax (%)", Type = UiColumnType.Number, Width = 100, TextAlign = UiTextAlign.Right, EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "SubTotal", HeaderText = "Sub Total", Type = UiColumnType.Number, Width = 110, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "TaxAmount", HeaderText = "Tax Amount", Type = UiColumnType.Number, Width = 110, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "ShipFee", HeaderText = "Ship Fee", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "TotalAmount", HeaderText = "Total Amount", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, Format = "C2", EditType = UiEditType.NumericEdit },
new UiGridColumn { Field = "PaymentMethod", HeaderText = "Payment Method", Width = 140, EditType = UiEditType.DropDownEdit, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "PaymentStatus", HeaderText = "Payment Status", Width = 140, TextAlign = UiTextAlign.Center, EditType = UiEditType.DropDownEdit, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "Rating", HeaderText = "Delivery Rating", Width = 160, TextAlign = UiTextAlign.Center, Visible = false, EditType = UiEditType.DropDownEdit }
}
})
<script>
var virtualOrderData = [], date1 = null, flag = true;
function createVirtualOrderData() {
if (window.virtualOrderData.length) { return; }
function pmRandom(seed) {
var t = (seed % 2147483647);
if (t <= 0) t += 2147483646;
return function () {
t = (t * 16807) % 2147483647;
return (t - 1) / 2147483646;
};
}
var seed = 123456789;
var rand = pmRandom(seed);
function randInt(min, max) { return Math.floor(rand() * (max - min + 1)) + min; }
function randChoice(arr) { return arr[Math.floor(rand() * arr.length)]; }
function pickAvoidTriplet(arr, fieldName) {
var v = randChoice(arr);
if (virtualOrderData.length >= 2) {
var a = virtualOrderData[virtualOrderData.length - 1][fieldName];
var b = virtualOrderData[virtualOrderData.length - 2][fieldName];
if (a === b && a === v) {
var alt = arr.filter(function (s) { return s !== v; });
v = randChoice(alt);
}
}
return v;
}
var names = ['Maria', 'Ana Trujillo', 'Antonio Moreno', 'Thomas Hardy', 'Christina Berglund', 'Hanna Moos', 'Frederique Citeaux', 'Martin Sommer', 'Laurence Lebihan', 'Elizabeth Lincoln',
'Victoria Ashworth', 'Patricio Simpson', 'Francisco Chang', 'Yang Wang', 'Pedro Afonso', 'Elizabeth Brown', 'Sven Ottlieb', 'Janine Labrune', 'Ann Devon', 'Roland Mendel', 'Aria Cruz', 'Diego Roel',
'Martine Rance', 'Maria Larsson', 'Peter Franken', 'Carine Schmitt', 'Paolo Accorti', 'Lino Rodriguez', 'Eduardo Saavedra', 'Jose Pedro Freyre', 'Andre Fonseca', 'Howard Snyder', 'Manuel Pereira',
'Mario Pontes', 'Carlos Hernández', 'Yoshi Latimer', 'Patricia McKenna', 'Helen Bennett', 'Philip Cramer', 'Daniel Tonini', 'Annette Roulet', 'Yoshi Tannamuri', 'John Steel', 'Renate Messner', 'Jaime Yorres',
'Carlos Gonzalez', 'Felipe Izquierdo', 'Fran Wilson', 'Giovanni Rovelli', 'Catherine Dewey', 'Jean Fresnière', 'Alexander Feuer', 'Simon Crowther', 'Yvonne Moncada', 'Rene Phillips', 'Henriette Pfalzheim',
'Marie Bertrand', 'Guillermo Fernandez', 'Georg Pipps', 'Isabel de Castro', 'Bernardo Batista', 'Lucia Carvalho', 'Horst Kloss', 'Sergio Gutierrez', 'Paula Wilson', 'Maurizio Moroni', 'Janete Limeira', 'Michael Holz',
'Alejandra Camino', 'Jonas Bergulfsen', 'Jose Pavarotti', 'Hari Kumar', 'Jytte Petersen', 'Dominique Perrier', 'Art Braunschweiger', 'Pascale Cartrain', 'Liz Nixon', 'Liu Wong', 'Karin Josephs', 'Miguel Angel Paolino',
'Anabela Domingues', 'Helvetius Nagy', 'Palle Ibsen', 'Mary Saveley', 'Paul Henriot', 'Rita Muller', 'Pirkko Koskitalo', 'Paula Parente', 'Karl Jablonski', 'Matti Karttunen', 'Zbyszek Piestrzeniewicz'];
var products = ['Chai','Chang','Aniseed Syrup','Chef Anton\'s Cajun Seasoning','Grandma\'s Boysenberry Spread','Uncle Bob\'s Organic Dried Pears','Mishi Kobe Niku','Ikura','Queso Cabrales','Pavlova'];
var categories = ['Beverages', 'Condiments', 'Confections', 'Dairy Products', 'Grains/Cereals', 'Meat/Poultry', 'Seafood'];
var paymentMethods = ['Card','Digital','Cash'];
var orderStatuses = ['Ordered','Processing','Packed','Shipped','Delivered','Canceled','Returned'];
var priorities = ['Low','Medium','High','Critical'];
var cities = ['Seattle','Austin','Boston','Chicago','San Francisco','New York'];
var states = ['WA','TX','MA','IL','CA','NY'];
var countries = ['USA','Canada','Mexico','UK','Germany','France'];
var warehouses = ['WH-A','WH-B','WH-C','WH-D'];
var productToCategory = (function(){
var m = {};
for (var pi = 0; pi < products.length; pi++) { m[products[pi]] = categories[pi % categories.length]; }
return m;
})();
function computeAmounts(qty, unitPrice, discountPct, taxPct, shippingFee) {
var gross = qty * unitPrice;
var discount = gross * (discountPct / 100);
var subtotal = gross - discount;
var tax = subtotal * (taxPct / 100);
var total = subtotal + tax + shippingFee;
return { subtotal: Math.round(subtotal * 100) / 100, taxAmount: Math.round(tax * 100) / 100, totalAmount: Math.round(total * 100) / 100 };
}
var baseTime = new Date(2025, 0, 1).getTime();
for (var i = 1; i <= 100000; i++) {
var qty = randInt(1, 10);
var unitPrice = Math.round((rand() * 500 + 5) * 100) / 100;
var discountPct = randInt(0, 20);
var taxPct = randInt(0, 18);
var shippingFee = Math.round((rand() * 20) * 100) / 100;
var amounts = computeAmounts(qty, unitPrice, discountPct, taxPct, shippingFee);
var orderDate = new Date(baseTime - randInt(0, 90) * 24 * 3600 * 1000);
var shippedDate = new Date(orderDate.getTime() + randInt(1, 14) * 24 * 3600 * 1000);
var customerId = randInt(1000, 9999);
var custName = randChoice(names);
var email = custName.toLowerCase().replace(/\s+/g, '.') + "@@example.com";
var paymentMethod = pickAvoidTriplet(paymentMethods, 'PaymentMethod');
var rating = randInt(1, 5);
var orderStatusVal = pickAvoidTriplet(orderStatuses, 'OrderStatus');
var priorityVal = pickAvoidTriplet(priorities, 'Priority');
var productName = randChoice(products);
var derivedCategory = productToCategory[productName] || randChoice(categories);
var warehouse = randChoice(warehouses);
var inventoryCount = randInt(0, 500);
var paymentStatus = (function(){
var ps = 'Pending';
if (orderStatusVal === 'Delivered' || orderStatusVal === 'Shipped') {
ps = 'Paid';
} else if (orderStatusVal === 'Canceled' || orderStatusVal === 'Returned') {
if (rating <= 1) {
ps = 'Failed';
} else {
ps = (paymentMethod === 'Cash') ? 'Pending' : 'Refunded';
}
} else if (orderStatusVal === 'Packed') {
ps = (paymentMethod === 'Cash') ? 'Pending' : 'Paid';
} else if (orderStatusVal === 'Ordered' || orderStatusVal === 'Processing') {
ps = 'Pending';
} else {
ps = 'Pending';
}
return ps;
})();
virtualOrderData.push({
OrderID: 'ORD-' + (1000 + i),
OrderDate: orderDate,
ShipDate: shippedDate,
CustomerID: 'CUS-' + customerId,
CustomerName: custName,
Email: email,
Phone: '+1-' + randInt(200,999) + '-' + randInt(1000,9999),
ShipAddress: randInt(10,999) + ' ' + randChoice(['Main St','Market St','1st Ave','Broadway']),
ShipCity: randChoice(cities),
ShipState: randChoice(states),
ShipPostalCode: '' + randInt(10000,99999),
ShipCountry: randChoice(countries),
ProductID: 'PROD-' + randInt(10000, 99999),
ProductName: productName,
Category: derivedCategory,
Quantity: qty,
UnitPrice: unitPrice,
Discount: discountPct,
Tax: taxPct,
SubTotal: amounts.subtotal,
TaxAmount: amounts.taxAmount,
ShipFee: shippingFee,
TotalAmount: amounts.totalAmount,
PaymentMethod: paymentMethod,
PaymentStatus: paymentStatus,
Warehouse: warehouse,
InventoryCount: inventoryCount,
Priority: priorityVal,
OrderStatus: orderStatusVal,
Rating: rating,
});
}
};
// Syncfusion's badge functions: each returns the HTML of one cell (built with textContent); here they fill the cell content.
function priorityDetail(e) {
var div = document.createElement('div');
var span = document.createElement('span');
if (e.Priority === 'High') {
span.className = 'virtual-statustxt e-highcolor';
span.textContent = 'High';
div.className = 'virtual-statustemp e-highcolor';
} else if (e.Priority === 'Low') {
span.className = 'virtual-statustxt e-lowcolor';
span.textContent = 'Low';
div.className = 'virtual-statustemp e-lowcolor';
} else if (e.Priority === 'Medium') {
span.className = 'virtual-statustxt e-mediumcolor';
span.textContent = 'Medium';
div.className = 'virtual-statustemp e-mediumcolor';
} else {
span.className = 'virtual-statustxt e-criticalcolor';
span.textContent = 'Critical';
div.className = 'virtual-statustemp e-criticalcolor';
}
div.appendChild(span);
return div.outerHTML;
};
function paymentStatusDetail(e) {
var div = document.createElement('div');
var span = document.createElement('span');
var val = (e.PaymentStatus || '').toString();
if (val === 'Paid') {
span.className = 'virtual-statustxt e-paidcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-paidcolor';
} else if (val === 'Pending') {
span.className = 'virtual-statustxt e-pendingcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-pendingcolor';
} else if (val === 'Refunded') {
span.className = 'virtual-statustxt e-refundcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-refundcolor';
} else {
span.className = 'virtual-statustxt e-failedcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-failedcolor';
}
div.appendChild(span);
return div.outerHTML;
};
function orderStatusDetail(e) {
var div = document.createElement('div');
var span = document.createElement('span');
var val = (e.OrderStatus || '').toString();
if (val === 'Delivered') {
span.className = 'virtual-statustxt e-deliveredcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-deliveredcolor';
} else if (val === 'Shipped') {
span.className = 'virtual-statustxt e-shippedcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-shippedcolor';
} else if (val === 'Packed') {
span.className = 'virtual-statustxt e-packedcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-packedcolor';
} else if (val === 'Processing') {
span.className = 'virtual-statustxt e-processingcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-processingcolor';
} else if (val === 'Canceled') {
span.className = 'virtual-statustxt e-cancelcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-cancelcolor';
} else if (val === 'Returned') {
span.className = 'virtual-statustxt e-returnedcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-returnedcolor';
} else {
span.className = 'virtual-statustxt e-orderedcolor';
span.textContent = val;
div.className = 'virtual-statustemp e-orderedcolor';
}
div.appendChild(span);
return div.outerHTML;
};
function show() { document.getElementById('popup').style.display = 'inline-block'; }
function hide() {
if (flag && date1) {
document.getElementById('performanceTime').textContent = 'Time Taken: ' + (new Date().getTime() - date1) + 'ms';
flag = false;
}
document.getElementById('popup').style.display = 'none';
}
function badge(html) {
var holder = document.createElement('div');
holder.innerHTML = html;
return holder.firstChild;
}
function queryCellInfo(args) {
if (args.column === 'OrderStatus') { args.content = badge(orderStatusDetail(args.data)); }
else if (args.column === 'Priority') { args.content = badge(priorityDetail(args.data)); }
else if (args.column === 'PaymentStatus') { args.content = badge(paymentStatusDetail(args.data)); }
else if (args.column === 'Rating') {
// Syncfusion's rating widget: five stars here
var stars = document.createElement('span');
stars.className = 'rating-stars';
var rating = Number(args.data.Rating) || 0;
for (var i = 1; i <= 5; i++) {
var star = document.createElement('span');
star.textContent = '\u2605';
if (i > rating) { star.className = 'off'; }
stars.appendChild(star);
}
args.content = stars;
}
}
// Syncfusion: the first click makes the 100,000 orders in the browser and binds the grid; the next ones read them again.
document.getElementById('generate').addEventListener('click', function () {
show();
flag = true;
date1 = new Date().getTime();
setTimeout(function () {
if (!virtualOrderData.length) { createVirtualOrderData(); }
window.Lumen.get('VirtualGrid').changeDataSource(virtualOrderData);
}, 30);
});
hide();
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class GridController : Controller
{
// The page is Views/Grid/VirtualScrolling.cshtml; it draws what ViewData holds.
public ActionResult VirtualScrolling()
{
// the 100,000 orders are made in the browser when Load 100K Data is clicked
return View();
}
}
}
@* Program.cs *@
builder.Services.AddControllersWithViews().AddLumenUIJson();
builder.Services.AddLumenUI();
// ...
app.UseLumenUI();
@* Views/_ViewImports.cshtml *@
@using Lumen.UI.Mvc
@addTagHelper *, Lumen.UI.Core
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@await RenderSectionAsync("scripts", required: false)
</body>
@* Grids with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
The virtual scrolling feature in the Grid renders only the rows and columns that are currently visible in the viewport, rather than loading the entire dataset into the DOM. This approach significantly improves performance when working with large data sources by reducing the number of DOM elements.
To enable row virtualization, set the EnableVirtualization property to true. For column virtualization, set the EnableColumnVirtualization property to true. When using virtualization, it is essential to define the Height property so that the Grid can accurately calculate the number of visible rows. For seamless scrolling, set args.enableSeamlessScrolling as true in the Grid's Load event. This ensures smooth vertical and horizontal transitions, providing a smoother experience during fast scrolling when virtualization is enabled.
In this example, click the "Load 100K Data" button to bind a dataset containing 100,000 rows and 30 columns. Then, scroll vertically and horizontally to experience the virtualized rendering in action. Full data editing support is available with the virtualization feature.
For more detailed information about virtual scrolling, refer to this documentation.