Capture user input directly in the grid and rearrange data with intuitive drag-and-drop interactions.
OpenGridX supports inline cell editing. For a column to be editable, you must set editable: true in its definition.
const columns = [
{ field: 'name', editable: true },
{ field: 'role', editable: true, type: 'singleSelect', valueOptions: ['Admin', 'Editor'] }
];When a cell edit is committed, the processRowUpdate callback is triggered.
<DataGrid
processRowUpdate={(newRow, oldRow) => {
// Save to your database/state here
const updatedRows = rows.map(r => r.id === newRow.id ? newRow : r);
setRows(updatedRows);
return newRow; // Return the new row to confirm saving
}}
onProcessRowUpdateError={(error) => {
console.error('Update failed:', error);
}}
/>Allows users to rearrange rows by dragging a handle.
- Set
rowReordering={true}on the grid. - Handle the
onRowOrderChangecallback.
<DataGrid
rowReordering={true}
onRowOrderChange={(params) => {
const { oldIndex, targetIndex } = params;
// Move logic
const newRows = [...rows];
const [moved] = newRows.splice(oldIndex, 1);
newRows.splice(targetIndex, 0, moved);
setRows(newRows);
}}
/>Important
Row reordering is usually disabled when sorting or filtering is active to prevent index confusion.
Users can drag column headers to change their horizontal order. This is enabled by default.
Use the disableColumnReorder prop to control this feature globally.
<DataGrid disableColumnReorder={true} />You can manage the column order state explicitly using columnOrder and onColumnOrderChange.
const [colOrder, setColOrder] = useState(['id', 'name', 'status']);
<DataGrid
columnOrder={colOrder}
onColumnOrderChange={(params) => {
// params.newOrder is the updated array of field strings
setColOrder(params.newOrder);
}}
/>To prevent a specific column from being moved, set reorderable: false in its definition.
const columns = [
{ field: 'id', reorderable: false }, // Stay pinned at start
{ field: 'name' }
];