SearchableGroupedList
Description
SearchableGroupedList is a versatile collection component designed to render a list of items that can be grouped and searched. It provides built-in search functionality to filter items based on input terms and organizes them by their respective groups. Use this component when you need to display a categorized list that supports live searching over a finite set of items. It is part of the Collections group in the UI toolkit.
Usage
Create a SearchableGroupedList by providing an array or an observable list of items that implement the ISearchableGroupedItem interface, along with a function to generate a header component for each group. The component includes a search box that filters items in real time, and you can further customize its behavior, such as adding custom content before or after the search box or setting a custom “no results” message.
Below is an example of how to instantiate the component:
API reference
public class SearchableGroupedList<T> : IComponent, ISpecialCaseStyling where T : ISearchableGroupedItemA searchable, scrollable list whose items are organized into named groups.
Constructors
public SearchableGroupedList(T[] items, Func<string, IComponent> groupedItemHeaderGenerator, params UnitSize[] columns) : this(new ObservableList<T>(initialValues: items ?? new T[0]), groupedItemHeaderGenerator, columns)Initializes a new instance of this class.
Properties
public HTMLElement StylingContainerGets or sets the styling container.
public bool PropagateToStackItemParentGets or sets the propagate to stack item parent.
Methods
public SearchableGroupedList<T> WithNoResultsMessage(Func<IComponent> emptyListMessageGenerator)Returns the component configured with the given no results message.
public SearchableGroupedList<T> WithGroupOrdering(IComparer<string> groupComparer)Returns the component configured with the given group ordering.
public SearchableGroupedList<T> SearchBox(Action<SearchBox> sb)Configures the inline search box using the supplied callback.
public SearchableGroupedList<T> CaptureSearchBox(out SearchBox sb)Captures the inline search box into the supplied variable for later reference.
public SearchableGroupedList<T> SetKeyboardShortcut(params string[] keys)Sets the keyboard shortcut of the component.
public SearchableGroupedList<T> BeforeSearchBox(params IComponent[] beforeComponents)Adds the given components before the inline search box.
public SearchableGroupedList<T> AfterSearchBox(params IComponent[] afterComponents)Adds the given components after the inline search box.
public SearchableGroupedList<T> Virtualize(UnitSize itemHeight)Configures the component to virtualize.
public HTMLElement Render()Renders the component's root HTML element.
public interface ISearchableGroupedItem : ISearchableItemSamples
Live-filtered Grouped List
This sample uses a dataset of 30 produce items spread across four groups. Type any term in the search box (for example "berry", "leaf", or "Fruits") and watch the list filter in real time — both the item name and the group name participate in matching.
Custom Group Ordering and Commands
WithGroupOrdering lets you control the display order of groups regardless of the order items arrive in. This sample also adds Filter and Add buttons around the search box, and uses a grid layout (three columns) for compact display.