Grouping in ASP.NET MVC AutoComplete

27 Aug 20261 minute to read

The AutoComplete supports grouping nested elements into categories. The category of each list item can be mapped through the groupBy field in the data table. The group header is displayed as both inline and fixed headers. The fixed group header content is updated dynamically on scrolling the suggestion list with its category value.

In the following sample, vegetables are grouped according to their category using the groupBy field.

@Html.EJS().AutoComplete("Vegetable").Placeholder("Select a Vegetable").PopupHeight("200px").DataSource((IEnumerable<object>)ViewBag.data).Fields(new Syncfusion.EJ2.DropDowns.AutoCompleteFieldSettings { Value = "Vegetable", GroupBy = "Category" }).Render()
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 AutoCompleteController : Controller
    {
       public ActionResult Index()
        {
            ViewBag.data = new Vegetables().VegetablesList();
            return View();
        }     
    }
}

Customization

The grouping header also provides customization options. This allows custom designing using the groupTemplate property for both inline and fixed headers as shown here:

Group template support in AutoComplete.

View Sample in GitHub.