Selection
Select rows with checkboxes, or by long-pressing a row. The toolbar shows the selected count and a clear action.
Basic usage
selection-bulk-actions.tsx
import { useState } from 'react';
import { Button, View } from 'react-native';
import { DataGrid, type GridRowId } from 'expo-flash-datagrid';
import { userColumns, users, type User } from './data';
export function BulkActionsScreen() {
const [selection, setSelection] = useState<GridRowId[]>([]);
const archiveSelected = () => {
console.log('archive', selection);
setSelection([]);
};
return (
<View style={{ flex: 1 }}>
<DataGrid<User>
mode="client"
rows={users}
columns={userColumns}
checkboxSelection
selectionModel={selection}
onSelectionModelChange={setSelection}
style={{ flex: 1 }}
/>
{selection.length > 0 ? (
<Button
title={`Archive ${selection.length}`}
onPress={archiveSelected}
/>
) : null}
</View>
);
}
Options
| Prop | Type | Default | Description |
|---|---|---|---|
selectionModel | GridRowId[] | [] | Controlled selected row IDs. |
onSelectionModelChange | (next: GridRowId[]) => void | None | Called when the selection changes. |
checkboxSelection | boolean | false | Adds a checkbox column. |
getRowId | (row) => string | row.id, then the row index | Identity stored in the selection. |
Behavior
- With
checkboxSelection, tapping a row toggles it, andonRowPressis not called. - Without it, a long press enters selection mode. It ends when the selection is empty.
- If the row has row actions on long press, the menu opens instead of selection mode.
Client vs server
Selection stores IDs and is independent of the mode. Selected IDs persist across pages, including rows no longer in rows.