View as Markdown

Searching

Searching

The toolbar search box, the search prop with its text, columns, operator and case and accent options, highlighted matches, search methods and events, and server-side search.

search turns grid search on: true for the defaults, or a DataGridSearch object. Search keeps the rows where any searched column matches the text, on top of the filters, and runs as a core pipeline stage.

The toolbar item 'search' hosts the search box: typing searches, Escape clears it, and a search made elsewhere is written back into the box. The box is a role="search" landmark labelled by the searchLabel text, "Search grid" by default; give each grid its own aria-label when a page has several. Enter applies the text at once; when a search changes the rows, a live region announces the match count ("12 rows match", localeText.searchMatches). DataGridSearchBox renders the same box elsewhere: inside the grid's subtree it finds the grid itself, outside it takes the grid's api (the grid ref). Its debounce (ms, default 0) delays typed text, aria-label names the landmark and onBeforeSearch can skip a search with preventDefault().

const [api, setApi] = useState<DataGridApi<Order> | null>(null);

<DataGridSearchBox api={api} debounce={200} aria-label="Search orders" />
<DataGrid onReady={setApi} data={orders} columns={columns} search />

Options

  • search.text is the search text. It is reactive and part of the server render, so a grid can render already searched. onBeforeSearchChange can cancel a change with preventDefault(); onSearchChange reports the text and the previousText.
  • search.fields lists the searched columns. By default every searchable column except date columns is searched; a column opts out with searchable: false.
  • search.operator is 'contains' (the default), 'startsWith', 'endsWith', 'equal', 'notEqual', 'wildcard' or 'like', with the filter operator names. 'wildcard' matches a pattern where * is any run of characters and ? one character (T*o finds "Tokyo"); 'like' is the SQL form where % (or *) is any run (%abc, abc%, %abc%). Both match the whole value, and number columns match their digits (1% finds 10 and 12). search.matchCase (default false) makes the match case-sensitive and search.ignoreAccents folds accents, so "jose" finds "José".

api.search(text) searches and api.clearSearch() clears the search; api.search('') clears it as well.

Highlighting matches

search.highlight: true wraps each match of the applied search in a <mark class="salmon-data-grid-search-mark"> inside the displayed text of the searched columns, without a cell template. The matches follow the search: the operator (contains marks every occurrence, startsWith and endsWith the start or the end, equal, wildcard and like the whole text, notEqual nothing), matchCase and ignoreAccents, so with accents ignored "jose" marks "José". Only rendered cells compute their marks, so the cost follows the visible cells, not the row count, and with the option off nothing is computed. <mark> is announced as highlighted text by screen readers that support it; forced-colors mode uses the system Mark colors. A renderCell template renders as given.

Search

Open demo

The toolbar search box over the search prop, with an initial text, the operator (including wildcard and like patterns), the searched columns, case and accent switches, highlighted matches, a non-searchable column, search methods and events.

Order
Customer
City
Country
Product
Amount
Note (not searchable)
ORD-10002
Chloé Dubois
Lyon
France
Filter beans
$79.80
ORD-10019
jose alvarez
Lyon
France
Oolong tea
$76.50
ORD-10020
Renée Roy
Lyon
France
Oolong tea
$130.05
ORD-10031
Ana Muñoz
Lyon
France
Filter beans
$151.20
ORD-10033
Zoë Laurent
Lyon
France
Espresso beans
$33.30
ORD-10052
Renée Roy
Lyon
France
Kettle
$551.65
ORD-10056
José Álvarez
Lyon
France
Grinder
$1,290.00
ORD-10066
Chloé Dubois
Lyon
France
Pour-over kit
$210.00
ORD-10072
José Álvarez
Lyon
France
Grinder
$1,315.80
Leave the parcel with the building reception if nobody answers the door.
ORD-10083
jose alvarez
Lyon
France
Espresso beans
$78.63
Leave the parcel with the building reception if nobody answers the door.
ORD-10095
Ana Muñoz
Lyon
France
Kettle
$554.90
ORD-10123
jose alvarez
Lyon
France
Green tea
$37.00
Leave the parcel with the building reception if nobody answers the door.
ORD-10136
José Álvarez
Lyon
France
Pour-over kit
$453.60
Leave the parcel with the building reception if nobody answers the door.
ORD-10139
jose alvarez
Lyon
France
Filter beans
$100.80
Gift wrap
ORD-10171
jose alvarez
Lyon
France
Filter beans
$126.00
ORD-10177
Zoë Laurent
Lyon
France
Green tea
$37.00
ORD-10180
Renée Roy
Lyon
France
Green tea
$111.00
Call before delivery
ORD-10192
José Álvarez
Lyon
France
Pour-over kit
$392.70
ORD-10205
André Silva
Lyon
France
Grinder
$387.00
ORD-10219
jose alvarez
Lyon
France
Pour-over kit
$285.60
Leave the parcel with the building reception if nobody answers the door.

Type in the toolbar search box; Escape clears it.

No events yet.

With a remote data source the search (text, fields, operator, case and accent options) is part of every read request, next to the filters and the page, and the server applies it. The request log of the server-side filtering demo shows it.

API reference

See DataGridSearch, DataGridSearchBoxProps and DataGridSearchChangeEvent in the API reference.