Limit the search result on filtering

12 Apr 20222 minutes to read

@Html.EJS().DropDownList("customers").Placeholder("Select a customer").PopupHeight("200px").DataSource(dataManger =>
                dataManger.Url("https://services.odata.org/V4/Northwind/Northwind.svc/").Adaptor("ODataV4Adaptor").CrossDomain(true)).AllowFiltering(true).Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings
                {
                    Value = "ContactName",
                }).Query("new ej.data.Query().from('Customers').select(['ContactName', 'CustomerID']).take(6)").Render()
    <script>
        function onfiltering(e) {
            var CBObj = document.getElementById("customers").ej2_instances[0];
            // load overall data when search key empty.
            if (e.text == '' && e.text.length < 3) {
                e.updateData(CBObj.dataSource);
            }
            let query = new ej.data.Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
            query = (e.text !== '' && e.text.length >= 3) ? query.where('ContactName', 'startswith', e.text, true) : query;
            e.updateData(CBObj.dataSource, query);
        }
    </script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class DropDownListController : Controller
    {
        public ActionResult limitsearch()
        {           
            return View();
        }
    }
}