Example of Grouping with CheckBox in ASP.NET MVC MultiSelect Control
This sample demonstrates the grouping functionalities of the MultiSelect in checkbox mode. Clicking the checkbox in group will select all the items grouped under it. Click the MultiSelect element and then type the character in the search box. It will display the filtered list items based on the typed characters and then select the multiple values through the checkbox.
@Html.UiMultiSelect("group", new UiMultiSelectOptions
{
PopupHeight = "200px",
Placeholder = "Select vegetables",
Mode = UiMultiSelectMode.CheckBox,
AllowFiltering = true,
ShowSelectAll = true,
FilterBarPlaceholder = "Search Vegetables",
EnableGroupCheckBox = true,
DataSource = (IEnumerable<DropdownsDemoController.Vegetables>)ViewData["data"],
Fields = new UiDropDownFields { GroupBy = "Category", Text = "Vegetable", Value = "Id" },
EnableSelectionOrder = false
})
<style>
.control-section .content { margin: 0 auto; width: 250px; }
.control-section h4 { margin: 0 0 8px; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div class="content" style="padding-top:15px">
<h4>Grouping with CheckBox</h4>
@Html.UiMultiSelect("group", new UiMultiSelectOptions
{
PopupHeight = "200px",
Placeholder = "Select vegetables",
Mode = UiMultiSelectMode.CheckBox,
AllowFiltering = true,
ShowSelectAll = true,
FilterBarPlaceholder = "Search Vegetables",
EnableGroupCheckBox = true,
DataSource = (IEnumerable<DropdownsDemoController.Vegetables>)ViewData["data"],
Fields = new UiDropDownFields { GroupBy = "Category", Text = "Vegetable", Value = "Id" },
EnableSelectionOrder = false
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MultiSelectController : Controller
{
// The page is Views/MultiSelect/GroupingWithCheckBox.cshtml; it draws what ViewData holds.
public ActionResult GroupingWithCheckBox()
{
ViewData["data"] = new Vegetables().VegetablesList();
return View();
}
public class Vegetables
{
public string Vegetable { get; set; }
public string Category { get; set; }
public string Id { get; set; }
public List<Vegetables> VegetablesList()
{
List<Vegetables> veg = new List<Vegetables>();
veg.Add(new Vegetables { Vegetable = "Cabbage", Category= "Leafy and Salad", Id= "item1" });
veg.Add(new Vegetables { Vegetable = "Chickpea", Category= "Beans", Id= "item2" });
veg.Add(new Vegetables { Vegetable = "Garlic", Category= "Bulb and Stem", Id= "item3" });
veg.Add(new Vegetables { Vegetable = "Green bean", Category= "Beans", Id= "item4" });
veg.Add(new Vegetables { Vegetable = "Horse gram", Category= "Beans", Id= "item5" });
veg.Add(new Vegetables { Vegetable = "Nopal", Category= "Bulb and Stem", Id= "item6" });
veg.Add(new Vegetables { Vegetable = "Onion", Category= "Bulb and Stem", Id= "item7" });
veg.Add(new Vegetables { Vegetable = "Pumpkins", Category= "Leafy and Salad", Id= "item8" });
veg.Add(new Vegetables { Vegetable = "Spinach", Category= "Leafy and Salad", Id= "item9" });
veg.Add(new Vegetables { Vegetable = "Wheat grass", Category= "Leafy and Salad", Id= "item10" });
veg.Add(new Vegetables { Vegetable = "Yarrow", Category = "Leafy and Salad", Id = "item11" });
return veg;
}
}
}
}
@* 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 MultiSelect has built-in support to select the multiple values through the checkbox, when the mode property is set to CheckBox. To perform the checkbox feature in MultiSelect, the CheckBoxSelection module should be injected in the application end.