-
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 - Deferred Selection
If you enable deferred row selection, the grid does not request selected rows' data with every selection change. For example, if a user clicks the checkbox in the column header to select all the rows, the grid does not immediately fetch all data from the server.
This is helpful in the following cases:
- You process data on the server and do not want to load the selected rows' data.
- You do process selected records on the client, but want to reduce the number of requests that are sent.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
import React, { useCallback, useState } from 'react';
import DataGrid, {
Column, DataGridTypes, FilterRow, Selection, Pager,
} from 'devextreme-react/data-grid';
import Button from 'devextreme-react/button';
import query from 'devextreme/data/query';
import 'devextreme/data/odata/store';
const MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24;
const dataSource = {
store: {
type: 'odata' as const,
version: 2,
url: 'https://js.devexpress.com/Demos/DevAV/odata/Tasks',
key: 'Task_ID',
},
expand: 'ResponsibleEmployee',
select: [
'Task_ID',
'Task_Subject',
'Task_Start_Date',
'Task_Due_Date',
'Task_Status',
'ResponsibleEmployee/Employee_Full_Name',
],
};
const selectionFilter = ['Task_Status', '=', 'Completed'];
let dataGrid;
const App = () => {
const [taskCount, setTaskCount] = useState(0);
const [peopleCount, setPeopleCount] = useState(0);
const [avgDuration, setAvgDuration] = useState(0);
const calculateStatistics = useCallback(async () => {
const selectedItems = await dataGrid.getSelectedRowsData();
const totalDuration = selectedItems.reduce((currentValue: number, item: { Task_Due_Date: number; Task_Start_Date: number; }) => {
const duration = item.Task_Due_Date - item.Task_Start_Date;
return currentValue + duration;
}, 0);
const averageDurationInDays = totalDuration / MILLISECONDS_IN_DAY / selectedItems.length;
setTaskCount(selectedItems.length);
setPeopleCount(
query(selectedItems)
.groupBy('ResponsibleEmployee.Employee_Full_Name')
.toArray().length,
);
setAvgDuration(Math.round(averageDurationInDays) || 0);
}, []);
const onInitialized = useCallback((e: DataGridTypes.InitializedEvent) => {
dataGrid = e.component;
calculateStatistics();
}, [calculateStatistics]);
return (
<div>
<DataGrid
id="grid-container"
dataSource={dataSource}
showBorders={true}
defaultSelectionFilter={selectionFilter}
onInitialized={onInitialized}
>
<Selection mode="multiple" deferred={true} />
<FilterRow visible={true} />
<Pager visible={true} />
<Column caption="Subject" dataField="Task_Subject" />
<Column
caption="Start Date"
dataField="Task_Start_Date"
width="auto"
dataType="date"
/>
<Column
caption="Due Date"
dataField="Task_Due_Date"
width="auto"
dataType="date"
/>
<Column
caption="Assigned To"
dataField="ResponsibleEmployee.Employee_Full_Name"
width="auto"
allowSorting={false}
/>
<Column caption="Status" width="auto" dataField="Task_Status" />
</DataGrid>
<div className="selection-summary center">
<Button
id="calculateButton"
text="Get statistics on the selected tasks"
type="default"
onClick={calculateStatistics}
/>
<div>
<div className="column">
<span className="text count">Task count:</span>
<span className="value">{taskCount}</span>
</div>
<div className="column">
<span className="text people-count">People assigned:</span>
<span className="value">{peopleCount}</span>
</div>
<div className="column">
<span className="text avg-duration">Average task duration (days):</span>
<span className="value">{avgDuration}</span>
</div>
</div>
</div>
</div>
);
};
export default App;
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
This demo illustrates the second scenario. Deferred selection is enabled and the selected rows are only requested when you click the button below the grid.
To enable deferred selection in your application, set the selection.deferred property to true.
To specify the initially selected rows, use the selectionFilter property. The DataGrid updates this property's value at runtime and you can always access the applied filter. In this demo, the selectionFilter selects rows whose Status
is Completed
.
To load the selected rows' data, call the getSelectedRowsData() method. In deferred selection mode, this method returns a Promise. You can access row data in its fulfillment handler. In this demo, the getSelectedRowsData() method gets data objects that are then used to calculate statistics for the selected tasks.