Skip to main content

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​

PropTypeDefaultDescription
selectionModelGridRowId[][]Controlled selected row IDs.
onSelectionModelChange(next: GridRowId[]) => voidNoneCalled when the selection changes.
checkboxSelectionbooleanfalseAdds a checkbox column.
getRowId(row) => stringrow.id, then the row indexIdentity stored in the selection.

Behavior​

  • With checkboxSelection, tapping a row toggles it, and onRowPress is 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.