SearchableList
Description
The SearchableList component is a generic list container designed to display and filter a collection of items that implement the ISearchableItem interface. It provides an integrated search box that allows users to search through the items by typing in a term. The component is highly customizable, supporting features such as custom "no results" messages, background search operations, and the addition of custom components before or after the search box. Use this component when you need a searchable list interface in your application.
Usage
Instantiate a SearchableList using the static helper methods from Tesserae.UI. It accepts an array or an ObservableList of items (each implementing ISearchableItem) and optional column widths for layout purposes. The search box filters items based on whether their IsMatch method returns true for each entered search term.
Below is a minimal sample demonstrating how to implement the ISearchableItem interface and create a SearchableList with a custom "no results" message:
API reference
public class SearchableList<T> : IComponent, ISpecialCaseStyling where T : ISearchableItemA searchable, scrollable list whose items are filtered live as the user types into a built-in search box.
- Namespace
- Tesserae
- Implements
- IComponent, ISpecialCaseStyling
Constructors
| Name | Description |
|---|---|
| SearchableList | Initializes a new instance of this class. |
| Overload | |
|---|---|
| SearchableList(T[], UnitSize[]) | Initializes a new instance of this class. |
| SearchableList(ObservableList<T>, UnitSize[]) | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| StylingContainer | Gets or sets the styling container. |
| PropagateToStackItemParent | Gets or sets the propagate to stack item parent. |
| Items | Adds the given items to the component. |
| ShowNotMatchingItems | Shows the not matching items. |
public HTMLElement StylingContainerGets or sets the styling container.
public bool PropagateToStackItemParentGets or sets the propagate to stack item parent.
public ObservableList<T> Items { get; }Adds the given items to the component.
Methods
| Name | Description |
|---|---|
| WithNoResultsMessage | Returns the component configured with the given no results message. |
| SearchBox | Configures the inline search box using the supplied callback. |
| CaptureSearchBox | Captures the inline search box into the supplied out variable for later reference. |
| SetKeyboardShortcut | Sets the keyboard shortcut of the component. |
| WithBackgroundSearch | Returns the component configured with the given background search. |
| HideSearchBoxIfLessThan | Hides the search box if less than. |
| ShowNotMatching | Shows the not matching. |
| BeforeSearchBox | Adds the given components before the inline search box. |
| AfterSearchBox | Adds the given components after the inline search box. |
| Virtualize | Configures the component to virtualize. |
| Render | Renders the component's root HTML element. |
| WithPagination | Returns the component configured with the given pagination. |
public SearchableList<T> WithNoResultsMessage(Func<IComponent> emptyListMessageGenerator)Returns the component configured with the given no results message.
public SearchableList<T> SearchBox(Action<SearchBox> sb)Configures the inline search box using the supplied callback.
public SearchableList<T> CaptureSearchBox(out SearchBox sb)Captures the inline search box into the supplied out variable for later reference.
public SearchableList<T> SetKeyboardShortcut(params string[] keys)Sets the keyboard shortcut of the component.
public SearchableList<T> WithBackgroundSearch(Func<string, Task<T[]>> searcher)Returns the component configured with the given background search.
public SearchableList<T> HideSearchBoxIfLessThan(int items)Hides the search box if less than.
public SearchableList<T> ShowNotMatching()Shows the not matching.
public SearchableList<T> BeforeSearchBox(params IComponent[] beforeComponents)Adds the given components before the inline search box.
public SearchableList<T> AfterSearchBox(params IComponent[] afterComponents)Adds the given components after the inline search box.
public SearchableList<T> Virtualize(UnitSize itemHeight)Configures the component to virtualize.
public dom.HTMLElement Render()Renders the component's root HTML element.
public interface ISearchableItem- Namespace
- Tesserae
Samples
Live Filtering with 50 Items
This sample produces 50 contact-style rows. Typing in the search box (try 7, Eve, or manager) filters the list as you type — when nothing matches, the custom "No Results" component is shown.
Searchable List with Background Search
WithBackgroundSearch lets you augment the local matches with results fetched asynchronously (for example from a backend). The delegate is invoked with the current search term after the user pauses typing, and its results are merged into the displayed list.