-
Data Grid
- Overview
-
Data Binding
-
Paging and Scrolling
-
Editing
-
Grouping
-
Filtering and Sorting
- Focused Row
-
Row Drag & Drop
-
Selection
-
Columns
- State Persistence
-
Appearance
-
Templates
-
Data Summaries
-
Master-Detail
-
Export to PDF
-
Export to Excel
-
Adaptability
- Keyboard Navigation
-
Pivot Grid
- Overview
-
Data Binding
-
Field Chooser
-
Features
-
Export to Excel
-
Tree List
- Overview
-
Data Binding
- Sorting
- Paging
-
Editing
- Node Drag & Drop
- Focused Row
-
Selection
-
Filtering
-
Column Customization
- State Persistence
- Adaptability
- Keyboard Navigation
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Features
- Virtual Scrolling
-
Grouping
-
Customization
- Adaptability
-
Html Editor
-
Chat
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
Charts
- Overview
-
Data Binding
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Line Charts
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
-
Sparkline Charts
-
Tree Map
-
Funnel and Pyramid Charts
- Sankey Chart
-
Combinations
-
More Features
-
Export
-
Selection
-
Tooltips
-
Zooming
-
-
Gantt
- Overview
-
Data
-
UI Customization
- Strip Lines
- Export to PDF
- Sorting
-
Filtering
-
Gauges
- Overview
-
Data Binding
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Navigation
- Overview
- Accordion
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
- Pagination
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Box
- Responsive Box
- Resizable
-
-
Editors
- Overview
- Autocomplete
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Drop Down Box
-
Number Box
-
Select Box
- Switch
-
Tag Box
- Text Area
- Text Box
- Validation
- Custom Text Editor Buttons
- Right-to-Left Support
- Editor Appearance Variants
-
Forms and Multi-Purpose
- Overview
- Button Group
- Field Set
-
Filter Builder
-
Form
- Radio Group
-
Range Selector
- Numeric Scale (Lightweight)
- Numeric Scale
- Date-Time Scale (Lightweight)
- Date-Time Scale
- Logarithmic Scale
- Discrete scale
- Custom Formatting
- Use Range Selection for Calculation
- Use Range Selection for Filtering
- Image on Background
- Chart on Background
- Customized Chart on Background
- Chart on Background with Series Template
- Range Slider
- Slider
-
Sortable
-
File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Actions and Lists
- Overview
-
Action Sheet
-
Button
- Floating Action Button
- Drop Down Button
-
Context Menu
-
List
-
Lookup
-
Maps
- Overview
-
Map
-
Vector Map
-
Dialogs and Notifications
-
Localization
React Data Grid - Command Column Customization
The DataGrid supports multiple predefined types of command columns. Each column type supports one type of action (edit, select, drag, etc.). This demo shows how to customize the Edit Command Column. This column type contains predefined edit buttons and optional custom buttons.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
import React, { useCallback, useState } from 'react';
import DataGrid, {
Button, Column, DataGridTypes, Editing, Lookup,
} from 'devextreme-react/data-grid';
import { employees as defaultEmployees, states, getMaxID } from './data.ts';
const isChief = (position: string) => position && ['CEO', 'CMO'].indexOf(position.trim().toUpperCase()) >= 0;
const isCloneIconVisible = (e) => !e.row.isEditing;
const isCloneIconDisabled = (e) => isChief(e.row.data.Position);
const isDeleteIconVisible = (e) => !isChief(e.row.data.Position);
const onRowValidating = (e: DataGridTypes.RowValidatingEvent) => {
const position = e.newData.Position;
if (isChief(position)) {
e.errorText = `The company can have only one ${position.toUpperCase()}. Please choose another position.`;
e.isValid = false;
}
};
const onEditorPreparing = (e: DataGridTypes.EditorPreparingEvent) => {
if (e.parentType === 'dataRow' && e.dataField === 'Position') {
e.editorOptions.readOnly = isChief(e.value);
}
};
const App = () => {
const [employees, setEmployees] = useState(defaultEmployees);
const onCloneIconClick = useCallback((e) => {
const clonedItem = { ...e.row.data, ID: getMaxID() };
setEmployees((prevState) => {
const updatedEmployees = [...prevState];
updatedEmployees.splice(e.row.rowIndex, 0, clonedItem);
return updatedEmployees;
});
e.event.preventDefault();
}, []);
return (
<DataGrid
id="gridContainer"
dataSource={employees}
keyExpr="ID"
showBorders={true}
onRowValidating={onRowValidating}
onEditorPreparing={onEditorPreparing}>
<Editing
mode="row"
useIcons={true}
allowUpdating={true}
allowDeleting={isDeleteIconVisible} />
<Column type="buttons" width={110}>
<Button name="edit" />
<Button name="delete" />
<Button hint="Clone" icon="copy" visible={isCloneIconVisible} disabled={isCloneIconDisabled} onClick={onCloneIconClick} />
</Column>
<Column dataField="Prefix" caption="Title" />
<Column dataField="FirstName" />
<Column dataField="LastName" />
<Column dataField="Position" width={130} />
<Column dataField="StateID" caption="State" width={125}>
<Lookup dataSource={states} displayExpr="Name" valueExpr="ID" />
</Column>
<Column dataField="BirthDate" dataType="date" width={125} />
</DataGrid>
);
};
export default App;
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
Predefined buttons
The available selection of predefined buttons depends on the selected edit mode, and the availability of the update and delete operations. To enable them, set the allowUpdating and allowDeleting properties to true. You can also set any of these properties to a custom function that enables the corresponding operation and displays its button only for certain rows.
This demo has the following configuration:
-
Edit mode is set to "row".
-
allowUpdating is enabled to display Edit buttons in all rows.
-
allowDeleting is set to a function that hides the Delete button based on a custom condition.
The predefined edit buttons are displayed as textual links by default. To use icons instead, set the useIcons property to true.
Custom buttons
If a command column should contain custom buttons, add its configuration to the columns array. DataGrid will display this column according to its position in this array. Specify the column's type as "buttons" and declare the buttons array. It should contain your custom buttons along with the predefined buttons. If you need to customize a predefined button, add an object with specified name and other button properties. If customization is not required, add only button names.
In this demo, the edit column contains one custom button (Clone) and two predefined buttons (Edit and Delete) without customization.