Skip to content

Filtering and Quick Search

Serenity grids support several ways to filter data: quick filters (inline editors in the toolbar), advanced filters (a filter panel/dialog with multiple conditions), and quick search (a text search box). All of these feed into the grid's RemoteView, which sends the filter criteria to the server with the list request.

Quick Filters

Quick filters are inline editors shown in the grid toolbar. They are derived from columns marked with quickFilter: true in the columns script, or defined manually via getQuickFilters().

A quick filter is a QuickFilter definition:

interface QuickFilter<TWidget, P> {
    field?: string;                    // field name
    type?: { new(options?: P): TWidget }; // widget constructor (editor)
    handler?: (h: QuickFilterArgs<TWidget>) => void; // custom request handling
    title?: string;                    // label
    options?: P & WidgetProps<{}>;     // editor options
    separator?: boolean;               // render a separator before
    cssClass?: string;
    pinned?: boolean;                  // stay visible while the bar is collapsed
    loadState?: (w, state) => void;    // restore persisted state
    saveState?: (w) => any;            // persist state
    displayText?: (w, label) => string;
}

The QuickFilterBar widget renders the filters and submits their values with list requests. When a filter changes, the grid reloads with the new criteria.

Bar Behavior

A QuickFilterBar is a widget of its own, and applications tune it once through QuickFilterBar.defaults:

Default Meaning
clearButton Show a Clear button after the last filter while any filter is applied (default true). It clears the filters, including the stateful ones through loadState, and emits a single change event, so the grid reloads once.
collapsible Collapse the filters that are not pinned behind a Filters button while the bar is narrower than collapseWidth (default true), see below.
collapseWidth The width in pixels below which the bar collapses (default 768, the width where hidden-xs filters used to disappear).
dateRangeFilter A factory for the date quick filter of a grid column, instead of QuickFilterBar.dateRange, e.g. an editor that edits the range in one input. It gets the quick filter params of the property as its third argument.
created / filterAdded Hooks called when a bar is created, and when a filter is added (after its widget is created), e.g. to give them classes.

The Filters button shows how many of the collapsed filters are applied and opens them one per row, so they stay usable on a phone. Filters can opt out of collapsing with pinned: true, which [QuickFilter(Pinned = true)] sets for a column (PropertyItem.QuickFilterPinned), so the one or two most used filters stay visible. Filters with the hidden-xs class are collapsed instead of hidden while the bar is narrow, so they can still be reached. The clear button stays after the last filter, or beside the toggle button while collapsed, instead of at the end of the bar, so a grid's view switch keeps its room.

[QuickFilter(Pinned = true)]
public string? ShipCity { get; set; }

The combobox editors that the bar creates turn on dropdownAutoWidth, so a long result is not clipped to the narrow width of the filter widget. Pass dropdownAutoWidth: false in the filter options to opt out.

Date Filters

A date column gets a date range editor by default. [QuickFilter(Range = false)] makes it edit a single date, which matches an exact value (e.g. the orders of a day): the attribute sends range: false in the quick filter params of the property, and the bar puts the value in the equality filter of the request instead of a range criteria.

[QuickFilter(Range = false)]
public DateTime? OrderDate { get; set; }

QuickFilterBar.dateRange(field, title, quickFilterParams) returns the single date filter when range is false in the params, and QuickFilterBar.dateEqual(field, title) builds it in code. An application's own QuickFilterBar.defaults.dateRangeFilter should honor the same option.

A quick filter's type can also be a promise-like widget type (a lazy import) when the editor is only loaded on demand: the bar renders a placeholder, and the saved state, value and handlers are kept until the real widget is ready (EditorFiltering behaves the same way).

Adding a Quick Filter

Quick filters are usually defined by marking a column with quickFilter: true in the columns script:

[QuickFilter]
public string ShipCity { get; set; }

You can also add them programmatically by overriding getQuickFilters():

protected override getQuickFilters() {
    const filters = super.getQuickFilters();
    filters.push({
        field: "OrderDate",
        type: DateEditor,
        title: "Order Date"
    });
    return filters;
}

A quick filter can also be a checklist (CheckList on the attribute, or a checkList editor), which is useful when a filter has many values, see Forms & Editors.

Advanced Filters

Advanced filters let users build complex conditions with multiple fields, operators, and parentheses. They are edited in a FilterPanel hosted in a FilterDialog.

The grid's filter bar (FilterDisplayBar) shows the active filters and provides the "Edit Filter" button that opens the FilterDialog. The FilterStore holds the filter lines and builds the criteria expression.

Filtering Types

Each field uses a filtering type that determines which operators and editor are available. Built-in filtering types include:

Filtering type Used for
StringFiltering Text fields
IntegerFiltering Integer fields
Int64Filtering 64-bit integer fields (pairs with Int64Editor)
DecimalFiltering Decimal fields
DateFiltering Date fields
DateTimeFiltering Date-time fields
BooleanFiltering Boolean fields
EnumFiltering Enum fields
LookupFiltering Lookup fields
ServiceLookupFiltering Service lookup fields
EditorFiltering Custom editor fields

The filtering type for a field is determined by its filteringType property (set from the [FilteringType] attribute or inferred from the field type). Custom filtering types are registered in the FilteringTypeRegistry.

Quick search is a text input in the toolbar that filters the grid by a search query. It is added by EntityGrid via createQuickSearchInput().

The QuickSearchInput widget:

  • Triggers a search after a short delay (typeDelay) once the user stops typing.
  • Supports selecting a search field (QuickSearchField) when multiple fields are configured.
  • Shows loading and filtered visual states.

You can customize the search fields by overriding getQuickSearchFields():

protected override getQuickSearchFields() {
    return [
        { name: "CustomerID", title: "Customer" },
        { name: "ShipCity", title: "Ship City" }
    ];
}

How Filters Reach the Server

  1. A quick filter changes or the user edits an advanced filter.
  2. The grid updates its RemoteView parameters (view.params).
  3. On the next populate(), the view builds a ListRequest including the filter criteria.
  4. The server applies the criteria and returns the filtered rows.

See Also