Client vs server mode
The required mode prop decides who transforms the rows.
| Step | mode="client" | mode="server" | mode="server" with serverSearchMode="localRows" |
|---|---|---|---|
| Filter | Grid | Your API | Your API |
| Search | Grid | Your API | Grid, on the current rows |
| Sort | Grid | Your API | Your API |
| Paginate | Grid | Your API | Your API |
Client mode
Use it when the full dataset is already in memory. The grid applies filter, search, sort, and paginate to rows, in that order.
client-mode.tsx
import { useState } from 'react';
import {
DataGrid,
type ColumnDef,
type QueryState,
} from 'expo-flash-datagrid';
import { initialQuery, users, type User } from './data';
const columns: ColumnDef<User>[] = [
{ field: 'name', headerName: 'Name', flex: 1.3, minWidth: 180 },
{ field: 'city', headerName: 'City', flex: 1, minWidth: 130 },
{ field: 'age', headerName: 'Age', type: 'number', width: 90 },
{
field: 'salary',
headerName: 'Salary',
type: 'number',
width: 120,
align: 'right',
headerAlign: 'right',
valueFormatter: (value) => `$${Number(value ?? 0).toFixed(0)}`,
},
{
field: 'registeredAt',
headerName: 'Registered',
type: 'date',
width: 130,
},
];
export function ClientModeScreen() {
const [query, setQuery] = useState<QueryState>(initialQuery);
return (
<DataGrid<User>
mode="client"
rows={users}
columns={columns}
state={query}
onStateChange={setQuery}
enableMultiSort
maxFilters={3}
searchDebounceMs={280}
pageSizeOptions={[10, 25, 50]}
zebraRows
style={{ flex: 1 }}
/>
);
}
Server mode
The grid renders rows as given and reports every change. Fetch the matching slice and pass the total as rowCount so the footer can page. Without rowCount, the grid falls back to rows.length.
server-pagination.tsx
import { useEffect, useState } from 'react';
import { DataGrid, type QueryState } from 'expo-flash-datagrid';
import { fetchUsers, initialQuery, userColumns, type User } from './data';
export function ServerPaginationScreen() {
const [query, setQuery] = useState<QueryState>(initialQuery);
const [rows, setRows] = useState<User[]>([]);
const [rowCount, setRowCount] = useState(0);
const [loading, setLoading] = useState(false);
useEffect(() => {
let stale = false;
setLoading(true);
fetchUsers(query)
.then((page) => {
if (stale) return;
setRows(page.rows);
setRowCount(page.total);
})
.finally(() => {
if (!stale) setLoading(false);
});
return () => {
stale = true;
};
}, [query]);
return (
<DataGrid<User>
mode="server"
rows={rows}
columns={userColumns}
rowCount={rowCount}
loading={loading}
state={query}
onStateChange={setQuery}
style={{ flex: 1 }}
/>
);
}
The query state your API receives has paginationModel, sortModel, filterModel, and searchText. See QueryState.
Hybrid search
Set serverSearchMode="localRows" when column filters and sorting belong to the API but the toolbar search should only narrow the rows you already have. See Search.