Pull down to refresh...
Release to refresh...
Refreshing...
-
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
Related Demos:
Your search did not match any results.
Loading...
React Data Grid - CRUD Operations
This demo shows how to implement remote CRUD operations in the CustomStore. You can view the server implementation under the DataGridWebApiController tab in the ASP.NET MVC version of this demo. The requests sent to the server are displayed under the DataGrid.
After a cell is edited, the DataGrid can behave differently depending on the selected refresh mode: reload data from the server (the refreshMode is full), reapply data processing operations (reshape), or merely rerender the changed cells (repaint).
To give you the ability to edit code on the fly, the demo uses SystemJS. For this reason, launching the demo takes some time. We strongly recommend that you do not use this approach in real projects.
Was this demo helpful?
Feel free to share demo-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Backend API
x
/* global RequestInit */
import React, { useCallback, useState } from 'react';
import {
DataGrid, Column, Editing, Scrolling, Lookup, Summary, TotalItem, DataGridTypes,
} from 'devextreme-react/data-grid';
import { Button } from 'devextreme-react/button';
import { SelectBox, SelectBoxTypes } from 'devextreme-react/select-box';
import CustomStore from 'devextreme/data/custom_store';
import { formatDate } from 'devextreme/localization';
import 'whatwg-fetch';
const refreshModeLabel = { 'aria-label': 'Refresh Mode' };
const URL = 'https://js.devexpress.com/Demos/Mvc/api/DataGridWebApi';
const REFRESH_MODES = ['full', 'reshape', 'repaint'];
const App = () => {
const [ordersData] = useState(new CustomStore({
key: 'OrderID',
load: () => sendRequest(`${URL}/Orders`),
insert: (values) => sendRequest(`${URL}/InsertOrder`, 'POST', {
values: JSON.stringify(values),
}),
update: (key, values) => sendRequest(`${URL}/UpdateOrder`, 'PUT', {
key,
values: JSON.stringify(values),
}),
remove: (key) => sendRequest(`${URL}/DeleteOrder`, 'DELETE', {
key,
}),
}));
const [customersData] = useState(new CustomStore({
key: 'Value',
loadMode: 'raw',
load: () => sendRequest(`${URL}/CustomersLookup`),
}));
const [shippersData] = useState(new CustomStore({
key: 'Value',
loadMode: 'raw',
load: () => sendRequest(`${URL}/ShippersLookup`),
}));
const [requests, setRequests] = useState([]);
const [refreshMode, setRefreshMode] = useState<DataGridTypes.GridsEditRefreshMode>('reshape');
const handleRefreshModeChange = useCallback((e: SelectBoxTypes.ValueChangedEvent) => {
setRefreshMode(e.value);
}, []);
const clearRequests = useCallback(() => {
setRequests([]);
}, []);
const logRequest = useCallback((method, url: string, data: Record<string, any>) => {
const args = Object.keys(data || {}).map((key) => `${key}=${data[key]}`).join(' ');
const time = formatDate(new Date(), 'HH:mm:ss');
const request = [time, method, url.slice(URL.length), args].join(' ');
setRequests((prevRequests: ConcatArray<string>) => [request].concat(prevRequests));
}, []);
const sendRequest = useCallback(async (url: string, method = 'GET', data = {}) => {
logRequest(method, url, data);
const request: RequestInit = {
method, credentials: 'include',
};
if (['DELETE', 'POST', 'PUT'].includes(method)) {
const params = Object.keys(data)
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`)
.join('&');
request.body = params;
request.headers = { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' };
}
const response = await fetch(url, request);
const isJson = response.headers.get('content-type')?.includes('application/json');
const result = isJson ? await response.json() : {};
if (!response.ok) {
throw result.Message;
}
return method === 'GET' ? result.data : {};
}, [logRequest]);
return (
<React.Fragment>
<DataGrid
id="grid"
showBorders={true}
dataSource={ordersData}
repaintChangesOnly={true}
>
<Editing
refreshMode={refreshMode}
mode="cell"
allowAdding={true}
allowDeleting={true}
allowUpdating={true}
/>
<Scrolling mode="virtual" />
<Column dataField="CustomerID" caption="Customer">
<Lookup dataSource={customersData} valueExpr="Value" displayExpr="Text" />
</Column>
<Column dataField="OrderDate" dataType="date" />
<Column dataField="Freight" />
<Column dataField="ShipCountry" />
<Column
dataField="ShipVia"
caption="Shipping Company"
dataType="number"
>
<Lookup dataSource={shippersData} valueExpr="Value" displayExpr="Text" />
</Column>
<Summary>
<TotalItem column="CustomerID" summaryType="count" />
<TotalItem column="Freight" summaryType="sum" valueFormat="#0.00" />
</Summary>
</DataGrid>
<div className="options">
<div className="caption">Options</div>
<div className="option">
<span>Refresh Mode: </span>
<SelectBox
value={refreshMode}
inputAttr={refreshModeLabel}
items={REFRESH_MODES}
onValueChanged={handleRefreshModeChange}
/>
</div>
<div id="requests">
<div>
<div className="caption">Network Requests</div>
<Button id="clear" text="Clear" onClick={clearRequests} />
</div>
<ul>
{requests.map((request, index) => <li key={index}>{request}</li>)}
</ul>
</div>
</div>
</React.Fragment>
);
};
export default App;
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx