Skip to main content

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 fieldTypeDefaultDescription
searchTextstring''Controlled search text.
onSearchTextChange(next: string) => voidNoneCalled when the text commits.
searchDebounceMsnumber300Debounce before the text commits.
column.searchablebooleantrueSet false to exclude a column.
serverSearchMode'remote' | 'localRows''remote'Where search runs in server mode.
serverLocalSearchTextstringNoneControlled text for localRows.
onServerLocalSearchTextChange(next: string) => voidNoneCalled when the local text commits.

A new search returns to the first page.

Client vs server​

  • mode="client": the grid searches rows.
  • mode="server": the grid reports searchText, and your API searches.
  • mode="server" with serverSearchMode="localRows": the grid searches only the current rows, 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.