DropdownList Server Filtering - allow NON case sensitive filtering

1 Answer 217 Views
DropDownList
adamhughes
Top achievements
Rank 1
Iron
Veteran
adamhughes asked on 13 Apr 2022, 07:17 PM

I notice in the sample for Server filtering (see below) of the Core Dropdown list the filter is Case Sensitive.  e.g. if I type in 'chef' ir will not find 'Chef'.  How can I make it NOT case-sensitive.  The Client side filter is not case-sensitive, only the server side.

see example Server filtering in ASP.NET Core DropDownList Component Demo | Telerik UI for ASP.NET Core

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 18 Apr 2022, 07:21 AM

Hello Adam,

The server side code used for the deme is:

public JsonResult ServerFiltering_GetProducts(string text)
        {
            using (var northwind = GetContext())
            {
                var products = northwind.Products.Select(product => new ProductViewModel
                {
                    ProductID = product.ProductID,
                    ProductName = product.ProductName,
                    UnitPrice = product.UnitPrice.Value,
                    UnitsInStock = product.UnitsInStock.Value,
                    UnitsOnOrder = product.UnitsOnOrder.Value,
                    Discontinued = product.Discontinued
                });

                if (!string.IsNullOrEmpty(text))
                {
                    products = products.Where(p => p.ProductName.Contains(text));
                }

                return Json(products.ToList());
            }
        }

The above can be updated to be case-insensitive by modifying the Where clause checking whether any products contain the input:

public JsonResult ServerFiltering_GetProducts(string text)
        {
            using (var northwind = GetContext())
            {
                var products = northwind.Products.Select(product => new ProductViewModel
                {
                    ProductID = product.ProductID,
                    ProductName = product.ProductName,
                    UnitPrice = product.UnitPrice.Value,
                    UnitsInStock = product.UnitsInStock.Value,
                    UnitsOnOrder = product.UnitsOnOrder.Value,
                    Discontinued = product.Discontinued
                });

                if (!string.IsNullOrEmpty(text))
                {
                    products = products.Where(p => p.ProductName.ToLower().Contains(text.ToLower()));
                }

                return Json(products.ToList());
            }
        }

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DropDownList
Asked by
adamhughes
Top achievements
Rank 1
Iron
Veteran
Answers by
Aleksandar
Telerik team
Share this question
or