DevExtreme React - First Steps
This step-by-step tutorial guides you through building a simple task list application with a progress bar. The completed application looks as follows:
The application includes two DevExtreme components: DataGrid and ProgressBar. The DataGrid displays tasks, and you can mark them as complete or incomplete. The ProgressBar above the DataGrid indicates task completion progress.
You can find the full source code in the GitHub repository:
Setup Your Project
Create an empty React JavaScript application (see React Documentation: Build a React app from Scratch). For instance, to create an application with Vite, run the following command:
- npm create vite@latest my-app -- --template react
Then, in the project file directory, run the following DevExtreme CLI command to add DevExtreme to your app:
- npx -p devextreme-cli devextreme add devextreme-react
For complete installation instructions, refer to the following help topic: Add DevExtreme to a React Application.
Style the App
DevExtreme offers over 40 predefined themes for component styling. You can also create a custom theme with our ThemeBuilder.
In the next step of the tutorial, apply the dx.fluent.blue.light theme and add CSS styles to the components.
To apply a theme, import a stylesheet where DevExtreme components are used or in the main application file:
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
If you want to apply theme colors and typography settings to all page elements (and not only to DevExtreme UI components), add a dx-viewport class to the <body> tag of your application's index.html file.
To configure component styles, create an index.css file and import it alongside the DevExtreme theme CSS file:
- :root {
- color-scheme: light; /* Update this property when you switch between light/dark themes. */
- }
- #dashboard {
- display: grid;
- gap: 20px;
- max-width: 900px;
- margin: 40px auto;
- padding: 80px 20px;
- box-sizing: border-box;
- }
- #progress,
- #task-grid {
- background-color: light-dark(#fff, #383838);
- padding: 16px;
- border-radius: 8px;
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
- }
Specify the Page Layout
Next, import components and specify their layout:
- import DataGrid from 'devextreme-react/data-grid';
- import ProgressBar from 'devextreme-react/progress-bar';
- function App(): JSX.Element {
- return(
- <div id="dashboard">
- <ProgressBar id="progress" />
- <DataGrid id="task-grid"></DataGrid>
- </div>
- );
- }
- export default App;
The dashboard is the container for two components: ProgressBar and DataGrid.
For detailed instructions on imports, refer to the Import DevExtreme Components help topic.
Bind DataGrid to Data
The DataGrid component can load and update data from different data source types. In this guide, a small local array serves as the data source. Follow these steps:
- Create the
tasksarray. - Assign the array to the dataSource property.
- Specify keyExpr (
idin this case). Use the nested
Columnconfiguration component to define columns you want to display. Remember to import the necessary configuration components.App.tsx- import DataGrid, { Column } from 'devextreme-react/data-grid';
- const tasks = [
- { id: 1, task: "Buy groceries", dueDate: new Date(), done: false },
- { id: 2, task: "Write a blog post", dueDate: new Date(), done: true }
- ];
- function App(): JSX.Element {
- return(
- <div id="dashboard">
- <ProgressBar id="progress" />
- <DataGrid
- id="task-grid"
- dataSource={tasks}
- keyExpr="id"
- >
- <Column dataField="task" />
- <Column dataField="dueDate" />
- <Column dataField="done" />
- </DataGrid>
- </div>
- );
- }
- export default App;
For more information about the nested configuration components, refer to the following help topics:
Configure Editing
The DataGrid component allows you to configure core features such as sorting, filtering, search, grouping, selection, and editing. Enable editing to allow users to add, edit, and delete rows.
This guide explains how to create a task list where users can check off tasks, remove them, and add new ones. To do this, specify the following editing options:
allowAdding
Set totrue- allows users to add new rows.allowDeleting
Set totrue- allows users to remove rows.allowUpdating
Set totrue- allows users to update rows.mode
Change the mode from the default "row" to "cell" for easy task status changes.newRowPosition
Set new rows to appear at the "last" position for a top-to-bottom task list.
- import DataGrid, { Column, Editing } from 'devextreme-react/data-grid';
- // ...
- function App(): JSX.Element {
- return(
- <div id="dashboard">
- <ProgressBar id="progress" />
- <DataGrid
- id="task-grid"
- dataSource={tasks}
- keyExpr="id"
- >
- <Editing
- mode="row"
- allowUpdating={true}
- allowAdding={true}
- allowDeleting={true}
- newRowPosition="last"
- />
- </DataGrid>
- </div>
- );
- }
- export default App;
Show Progress
At this point of the tutorial, you have created a DataGrid that stores task records and allows users to edit them. To display task progress, you integrated a ProgressBar into the layout. The next steps are to configure the ProgressBar options and synchronize it with DataGrid updates.
Configure ProgressBar
Manage the progress bar state with React useState Hook. Set the Hook initial value to 50, as half of the tasks in the initial list are completed. Bind the value option to the progressValue variable. setProgressValue keeps ProgressBar and DataGrid synchronized.
- import { useState } from 'react';
- import ProgressBar from 'devextreme-react/progress-bar';
- function App(): JSX.Element {
- const [progressValue, setProgressValue] = useState(50);
- return(
- <div id="dashboard">
- <ProgressBar
- value={progressValue}
- />
- <DataGrid ... ></DataGrid>
- </div>
- );
- }
- export default App;
Sync ProgressBar with DataGrid
To synchronize ProgressBar with DataGrid, define an updateProgress function. This function checks completed tasks and updates the ProgressBar value using the progressValue variable. Use this function to handle the following DataGrid events: onRowUpdated, onRowInserted, and onRowRemoved.
- function App(): JSX.Element {
- const [progressValue, setProgressValue] = useState(50);
- function updateProgress() {
- const all = tasks.length;
- const completed = tasks.filter((t) => t.done).length;
- setProgressValue(Math.round((completed / all) * 100));
- };
- return(
- <div id="dashboard">
- <ProgressBar ... />
- <DataGrid ...
- onRowUpdated={updateProgress}
- onRowInserted={updateProgress}
- onRowRemoved={updateProgress}
- >
- </DataGrid>
- </div>
- );
- }
- export default App;
Customize the App
Apply styles and templates to DevExtreme components to customize your app appearance.
Specify CSS Styles
DevExtreme components assign classes to nested elements. You can specify custom CSS styles for these classes to customize your app. For a list of common DevExtreme classes, refer to the following topic: CSS Classes.
This example applies rounded corners to the first and last rows of the DataGrid:
- #task-grid .dx-datagrid-headers, #task-grid .dx-datagrid .dx-datagrid-table .dx-header-row>td:first-child {
- border-top-left-radius: 8px;
- }
- #task-grid .dx-datagrid-headers, #task-grid .dx-datagrid .dx-datagrid-table .dx-header-row>td:last-child {
- border-top-right-radius: 8px;
- }
- #task-grid .dx-datagrid-rowsview {
- border-bottom-left-radius: 8px;
- border-bottom-right-radius: 8px;
- border-bottom-style: none;
- }
DevExtreme defines multiple theme-dependent CSS variables. You can use these variables to customize UI elements. This example applies the --dx-color-danger variable to "Delete" buttons in DataGrid rows:
- .dx-link-delete::before {
- color: var(--dx-color-danger)
- }
This example also customizes row deletion popups. The following styles stretch the nested Toolbar component to align dialog buttons with the dialog text:
- .dx-dialog .dx-toolbar-center {
- margin: -8px !important;
- width: calc(100% + 16px);
- border-spacing: 8px 0;
- float: none !important;
- }
- .dx-toolbar-center .dx-button {
- width: 100%;
- }
- .dx-toolbar-center .dx-item {
- padding-right: 0 !important;
- }
Configure Templates
DevExtreme components allow you to specify custom markup for certain elements. To specify custom markup, configure templates.
This example hides the DataGrid toolbar and specifies a columns[].headerCellTemplate to display an "Add a row" button in the header row. Integrate a DevExtreme Button within this template and call DataGrid.addRow() in the button's onClick handler:
- import { DataGrid, Column, Toolbar, type DataGridTypes } from 'devextreme-react/data-grid';
- import { Button } from 'devextreme-react/button';
- import notify from 'devextreme/ui/notify';
- import dxDataGrid from 'devextreme/ui/data_grid';
- // ...
- function createAddClickHandler(grid: dxDataGrid): () => void {
- return () => {
- grid.addRow().catch((error) => {
- // addRow() returns a promise. This code satisfies the no-floating-promises lint rule.
- notify(error);
- });
- };
- }
- function renderButtonColumnHeader(data: DataGridTypes.ColumnHeaderCellTemplateData): JSX.Element {
- return (
- <Button
- icon='add'
- stylingMode='text'
- onClick={createAddClickHandler(data.component)}
- />
- );
- }
- function App(): JSX.Element {
- // ...
- return (
- <DataGrid>
- <Column
- type='buttons'
- headerCellRender={renderButtonColumnHeader}
- />
- <Toolbar
- visible={false}
- />
- {/* ... */}
- </DataGrid>
- );
- }
This example also configures columns[].cellTemplate to implement placeholder values for empty cells and format date values (formatDate()):
- import { DataGrid, Column, type DataGridTypes } from 'devextreme-react/data-grid';
- import { formatDate } from 'devextreme/localization';
- // ...
- function renderTaskCell(data: DataGridTypes.ColumnCellTemplateData): JSX.Element {
- if (!data.value) {
- return (
- <div style={{ color: 'var(--dx-color-icon)' }}>Enter a title...</div>
- );
- }
- return (
- <div>{data.value}</div>
- );
- }
- function renderDueDateCell(data: DataGridTypes.ColumnCellTemplateData): JSX.Element {
- if (!data.value) {
- return (
- <div style={{ color: 'var(--dx-color-icon)' }}>Enter a date...</div>
- );
- }
- return (
- <div>{formatDate(data.value, 'shortDate')}</div>
- );
- }
- function App(): JSX.Element {
- // ...
- return (
- <DataGrid>
- <Column
- dataField='task'
- cellRender={renderTaskCell}
- />
- <Column
- dataField='dueDate'
- cellRender={renderDueDateCell}
- />
- {/* ... */}
- </DataGrid>
- );
- }
You can find the full source code of this example in the following GitHub repository:
Explore More
To learn more about DevExtreme, refer to the following sources:
Learn the basics of Component Configuration Syntax.
Edit and copy code from over 450 DevExtreme demos or our UI Template Gallery.
To learn more about a specific component, review guides and API references in the documentation. For common issues, refer to the following resources:
Need help? Submit a ticket to the DevExpress Support Center.