Example of grouping in ASP.NET MVC MultiColumnComboBox Control
This sample demonstrates grouping feature of the MultiColumn Combobox.
@Html.UiMultiColumnComboBox("grouping", new UiMultiColumnComboBoxOptions
{
Placeholder = "e.g. Laptop",
Fields = new UiDropDownFields { Text = "Name", Value = "Name", GroupBy = "Category" },
Columns = new List<UiDropDownColumn>
{
new UiDropDownColumn { Field = "Name", Header = "Name", Width = 110 },
new UiDropDownColumn { Field = "Price", Header = "Price", Width = 85 },
new UiDropDownColumn { Field = "Availability", Header = "Availability", Width = 98 },
new UiDropDownColumn { Field = "Category", Header = "Category", Width = 95 },
new UiDropDownColumn { Field = "Rating", Header = "Rating", Width = 70 }
},
PopupHeight = "210px",
PopupWidth = "500px",
AllowSorting = false,
DataSource = (IEnumerable<DropdownsDemoController.Products>)ViewData["data"]
})
<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
<div class="control-section">
<div class="control-wrapper">
<label>Select a product</label>
@Html.UiMultiColumnComboBox("grouping", new UiMultiColumnComboBoxOptions
{
Placeholder = "e.g. Laptop",
Fields = new UiDropDownFields { Text = "Name", Value = "Name", GroupBy = "Category" },
Columns = new List<UiDropDownColumn>
{
new UiDropDownColumn { Field = "Name", Header = "Name", Width = 110 },
new UiDropDownColumn { Field = "Price", Header = "Price", Width = 85 },
new UiDropDownColumn { Field = "Availability", Header = "Availability", Width = 98 },
new UiDropDownColumn { Field = "Category", Header = "Category", Width = 95 },
new UiDropDownColumn { Field = "Rating", Header = "Rating", Width = 70 }
},
PopupHeight = "210px",
PopupWidth = "500px",
AllowSorting = false,
DataSource = (IEnumerable<DropdownsDemoController.Products>)ViewData["data"]
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MultiColumnComboBoxController : Controller
{
// The page is Views/MultiColumnComboBox/Grouping.cshtml; it draws what ViewData holds.
public ActionResult Grouping()
{
ViewData["data"] = new Products().GetAllRecords();
return View();
}
public class Products
{
public string Name { get; set; }
public string Price { get; set; }
public string Availability { get; set; }
public string Category { get; set; }
public double Rating { get; set; }
public List<Products> GetAllRecords()
{
List<Products> products = new List<Products>();
products.Add(new Products { Name = "Laptop", Price = "999.99m", Availability = "In Stock", Category = "Electronics", Rating = 4.5 });
products.Add(new Products { Name = "Smartphone", Price = "599.99m", Availability = "Out of Stock", Category = "Electronics", Rating = 4.3 });
products.Add(new Products { Name = "Tablet", Price = "299.99m", Availability = "In Stock", Category = "Electronics", Rating = 4.2 });
// ... 17 more rows
return products;
}
}
}
}
@* 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 MultiColumn ComboBox allows to group the relevant items under a corresponding category by mapping the GroupBy property in the MultiColumnComboBoxFieldSettings which allows to load the list of employees. In this sample, the employee data is grouped against Category column, which illustrates how the employee details are grouped based on its category.