Example of virtualization in ASP.NET MVC MultiColumnComboBox Control
This example demonstrates the virtualization support in the MultiColumn ComboBox. It has 150 items bound to it. However, when you open the suggestion list only few items are loaded based on the popup height and the remaining items are loaded while scrolling.
@Html.UiMultiColumnComboBox("virtual", new UiMultiColumnComboBoxOptions
{
Placeholder = "e.g. Alice Johnson",
Fields = new UiDropDownFields { Text = "Name", Value = "Name" },
Columns = new List<UiDropDownColumn>
{
new UiDropDownColumn { Field = "Name", Header = "Name", Width = 100 },
new UiDropDownColumn { Field = "Departments", Header = "Departments", Width = 100 },
new UiDropDownColumn { Field = "Role", Header = "Role", Width = 90 },
new UiDropDownColumn { Field = "Location", Header = "Location", Width = 90 }
},
DataSource = Model.Records,
PopupHeight = "210px",
PopupWidth = "585px",
EnableVirtualization = true
})
<style>
.control-section .control-wrapper { margin: 0 auto; width: 300px; padding-top: 30px; }
.control-section .control-wrapper label { display: block; margin-bottom: 6px; font-weight: 600; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
@model DropdownsDemoController.MultiColumnComboBoxRecord
<div class="control-section">
<div class="control-wrapper">
<label>Select an employee</label>
@Html.UiMultiColumnComboBox("virtual", new UiMultiColumnComboBoxOptions
{
Placeholder = "e.g. Alice Johnson",
Fields = new UiDropDownFields { Text = "Name", Value = "Name" },
Columns = new List<UiDropDownColumn>
{
new UiDropDownColumn { Field = "Name", Header = "Name", Width = 100 },
new UiDropDownColumn { Field = "Departments", Header = "Departments", Width = 100 },
new UiDropDownColumn { Field = "Role", Header = "Role", Width = 90 },
new UiDropDownColumn { Field = "Location", Header = "Location", Width = 90 }
},
DataSource = Model.Records,
PopupHeight = "210px",
PopupWidth = "585px",
EnableVirtualization = true
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MultiColumnComboBoxController : Controller
{
// The page is Views/MultiColumnComboBox/Virtualization.cshtml; it draws what ViewData holds.
public ActionResult Virtualization()
{
MultiColumnComboBoxRecord model = new MultiColumnComboBoxRecord();
model.Records = new MultiColumnComboBoxRecord().GenerateTasks(150);
return View(model);
}
public class MultiColumnComboBoxRecord
{
public string Name { get; set; }
public string Departments { get; set; }
public string Role { get; set; }
public string Location { get; set; }
public List<MultiColumnComboBoxRecord> Records { get; set; }
// Syncfusion picks each value by chance; here it goes by the row number, so the page is the same on every visit.
public List<MultiColumnComboBoxRecord> GenerateTasks(int count)
{
var names = new List<string> { "John Doe", "Jane Smith", "Alice Johnson", "Bob Brown", "Emily Davis" };
var departments = new List<string> { "HR", "IT", "Finance", "Marketing", "Sales" };
var roles = new List<string> { "Manager", "Developer", "Analyst", "Consultant", "Executive" };
var locations = new List<string> { "New York", "San Francisco", "London", "Berlin", "Tokyo" };
var result = new List<MultiColumnComboBoxRecord>();
for (var i = 0; i < count; i++)
{
result.Add(new MultiColumnComboBoxRecord
{
Name = names[i % names.Count],
Departments = departments[(i / 2) % departments.Count],
Role = roles[(i / 3) % roles.Count],
Location = locations[(i / 5) % locations.Count]
});
}
return result;
}
}
/// <summary>A row of the virtual-scrolling samples.</summary>
public class RecordInfo
{
public int Id { get; set; }
public string Text { get; set; }
}
private static readonly List<RecordInfo> RecordList = Enumerable.Range(1, 1000).Select(i => new RecordInfo { Id = i, Text = "Record " + i }).ToList();
/// <summary>DataUrl of the virtual-scrolling sample: 1,000 records, read a page at a time (skip, take, requiresCounts).</summary>
[HttpPost]
[ValidateJsonAntiForgeryToken]
public ActionResult Records(UiDataRequest request)
{
return Json(UiDataOperations.Execute(RecordList.AsQueryable(), request, "Id"));
}
}
}
@* 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>
@* Dropdowns with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
The MultiColumn ComboBox supports virtualization, which improves UI performance for large amounts of data. To enable virtualization, set the EnableVirtualization property to true. When virtualization is enabled, MultiColumn ComboBox doesn't render the entire suggestion data source on initial rendering. It loads the N number of items in the popup on initial rendering and the remaining set number of items will load while scrolling. Virtualization works with both local and remote data.