Row actions
rowActions opens a menu for a row, by default on long press. Pass an array, or a function to build items per row.
Basic usage
row-actions.tsx
import { MaterialIcons } from '@expo/vector-icons';
import {
DataGrid,
type GridRowActionsSource,
type RowActionMenuIconProps,
} from 'expo-flash-datagrid';
import { userColumns, users, type User } from './data';
function EditIcon({ color, size }: RowActionMenuIconProps) {
return <MaterialIcons name="edit" color={color} size={size} />;
}
function DeleteIcon({ color, size }: RowActionMenuIconProps) {
return <MaterialIcons name="delete" color={color} size={size} />;
}
const rowActions: GridRowActionsSource<User> = ({ row }) => [
{
key: 'edit',
label: 'Edit',
icon: EditIcon,
disabled: !row.active,
onPress: ({ rowId }) => console.log('edit', rowId),
},
{
key: 'delete',
label: 'Delete',
icon: DeleteIcon,
destructive: true,
onPress: ({ rowId }) => console.log('delete', rowId),
},
];
export function RowActionsScreen() {
return (
<DataGrid<User>
mode="client"
rows={users}
columns={userColumns}
rowActions={rowActions}
onRowActionMenuOpen={({ rowId, actions }) =>
console.log(rowId, actions.length)
}
style={{ flex: 1 }}
/>
);
}
Options
| Prop | Type | Default | Description |
|---|---|---|---|
rowActions | GridRowActionsSource | None | Items, or a function returning them. |
rowActionMenuTrigger | 'none' | 'longPress' | 'longPress' when rowActions is set | Set 'none' to keep long press for selection. |
onRowActionMenuOpen | (params: RowActionMenuOpenParams) => void | None | Called when the menu opens. |
GridRowActionItem
| Field | Type | Description |
|---|---|---|
key | string | Unique key. |
label | string | Menu text. |
icon | GridRowActionIcon | A node, or a function receiving { color, size }. |
cellLabel | string | Text used in an actions column. |
displayInCell | 'icon' | 'label' | 'both' | How an actions column shows it. |
disabled | boolean | Shows the item as unavailable. |
destructive | boolean | Styles the item as dangerous. |
onPress | (params: RowLongPressParams) => void | Receives row, rowId, and position. |
The menu does not open when the source returns an empty list.
Client vs server
Row actions work the same in both modes. After a change, refresh rows or refetch.