Search
The toolbar search looks through every column except actions columns. It matches raw values, valueFormatter output, and filterSelectOptions labels and values.
Basic usage
search.tsx
import { useState } from 'react';
import { DataGrid, type ColumnDef } from 'expo-flash-datagrid';
import { users, type User } from './data';
const columns: ColumnDef<User>[] = [
{ field: 'name', headerName: 'Name', flex: 1, minWidth: 160 },
{ field: 'city', headerName: 'City', width: 130 },
{ field: 'email', headerName: 'Email', width: 200, searchable: false },
];
export function SearchScreen() {
const [searchText, setSearchText] = useState('');
return (
<DataGrid<User>
mode="client"
rows={users}
columns={columns}
searchText={searchText}
onSearchTextChange={setSearchText}
searchDebounceMs={200}
style={{ flex: 1 }}
/>
);
}
Options
| Prop or field | Type | Default | Description |
|---|---|---|---|
searchText | string | '' | Controlled search text. |
onSearchTextChange | (next: string) => void | None | Called when the text commits. |
searchDebounceMs | number | 300 | Debounce before the text commits. |
column.searchable | boolean | true | Set false to exclude a column. |
serverSearchMode | 'remote' | 'localRows' | 'remote' | Where search runs in server mode. |
serverLocalSearchText | string | None | Controlled text for localRows. |
onServerLocalSearchTextChange | (next: string) => void | None | Called when the local text commits. |
A new search returns to the first page.
Client vs server
mode="client": the grid searchesrows.mode="server": the grid reportssearchText, and your API searches.mode="server"withserverSearchMode="localRows": the grid searches only the currentrows, and emits no new query.
server-local-search.tsx
import { useEffect, useState } from 'react';
import { DataGrid, type QueryState } from 'expo-flash-datagrid';
import { fetchUsers, initialQuery, userColumns, type User } from './data';
export function HybridSearchScreen() {
const [query, setQuery] = useState<QueryState>(initialQuery);
const [rows, setRows] = useState<User[]>([]);
const [rowCount, setRowCount] = useState(0);
const [localSearch, setLocalSearch] = useState('');
useEffect(() => {
let stale = false;
fetchUsers(query).then((page) => {
if (stale) return;
setRows(page.rows);
setRowCount(page.total);
});
return () => {
stale = true;
};
}, [query]);
return (
<DataGrid<User>
mode="server"
serverSearchMode="localRows"
serverLocalSearchText={localSearch}
onServerLocalSearchTextChange={setLocalSearch}
rows={rows}
columns={userColumns}
rowCount={rowCount}
state={query}
onStateChange={setQuery}
style={{ flex: 1 }}
/>
);
}
With a local search active, paged mode shows the match count in the footer range and keeps page navigation based on rowCount. Infinite mode shows the match count for the rows loaded so far.
The toolbar's Clear filters action resets searchText, serverLocalSearchText, filterModel, and columnVisibilityModel.