Example of sorting in ASP.NET MVC MultiColumnComboBox Control
This example demonstrates the sorting support in the MultiColumn ComboBox.
@Html.UiMultiColumnComboBox("sorting", new UiMultiColumnComboBoxOptions
{
Placeholder = "e.g. laptop",
Fields = new UiDropDownFields { Text = "Name", Value = "Name" },
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 = "600px",
SortOrder = UiDropDownSortOrder.Ascending,
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("sorting", new UiMultiColumnComboBoxOptions
{
Placeholder = "e.g. laptop",
Fields = new UiDropDownFields { Text = "Name", Value = "Name" },
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 = "600px",
SortOrder = UiDropDownSortOrder.Ascending,
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/Sorting.cshtml; it draws what ViewData holds.
public ActionResult Sorting()
{
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>
In this sample, you can click the column header to sort/unsort the column. Any field can be selected from the Fields dropdown list and its order can be changed to display headers either in ascending or descending order. Sorting can be enabled using the AllowSorting property and the sort order can be customized using the SortOrder property in the MultiColumn ComboBox.