Example of Filtering in ASP.NET MVC MultiSelect Control
This sample demonstrates the filtering functionalities of the MultiSelect. Type a character in the MultiSelect element and choose one or more items from the filtered list.
@Html.UiMultiSelect("list", new UiMultiSelectOptions
{
AllowFiltering = true,
Placeholder = "Select countries",
DataSource = (IEnumerable<DropdownsDemoController.CountriesData>)ViewData["data"],
Fields = new UiDropDownFields { Text = "Name", Value = "Code" },
DebounceDelay = 300
})
@Html.UiNumericTextBox("numeric", new UiNumericTextBoxOptions { Format = "n0", Value = 300, Min = 1, OnChange = "change" })
<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" style="height: 400px;">
<div class="content" style="padding-top:15px">
<h4>Filtering</h4>
@Html.UiMultiSelect("list", new UiMultiSelectOptions
{
AllowFiltering = true,
Placeholder = "Select countries",
DataSource = (IEnumerable<DropdownsDemoController.CountriesData>)ViewData["data"],
Fields = new UiDropDownFields { Text = "Name", Value = "Code" },
DebounceDelay = 300
})
</div>
</div>
<div class="demo-property-panel" title="Properties">
<div class="demo-property-row">
<label class="example-label">Debounce Delay</label>
@Html.UiNumericTextBox("numeric", new UiNumericTextBoxOptions { Format = "n0", Value = 300, Min = 1, OnChange = "change" })
</div>
</div>
<script>
// Syncfusion: the debounceDelay of the MultiSelect is the value of the NumericTextBox.
function change(value) {
window.Lumen.get('list').setDebounceDelay(value);
}
</script>
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/Filtering.cshtml; it draws what ViewData holds.
public ActionResult Filtering()
{
ViewData["data"] = new CountriesData().CountriesList();
ViewData["query"] = "new ej.data.Query()";
return View();
}
public class CountriesData
{
public string Name { get; set; }
public string Code { get; set; }
public List<CountriesData> CountriesList()
{
List<CountriesData> country = new List<CountriesData>();
country.Add(new CountriesData { Name = "Australia", Code = "AU" });
country.Add(new CountriesData { Name = "Bermuda", Code = "BM" });
country.Add(new CountriesData { Name = "Canada", Code = "CA" });
// ... 16 more rows
return country;
}
}
}
}
@* 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 filter the data source when allowFiltering is enabled. It performs when characters are typed in the component. In filtering event, you can filter down the data source and return the resulted data to MultiSelect via updateData method to display its list items.
This sample illustrates that, query the data source and pass the resulted data to MultiSelect through the updateData method in filtering event. The debounce delay, in milliseconds, for filtering items in the MultiSelect component can be set using the DebounceDelay property.