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 - Focused Row
The DataGrid component can highlight the focused row. To enable this feature, set the focusedRowEnabled property to true.
To focus a row programmatically, specify the focusedRowKey property. The DataGrid automatically scrolls to the focused row if the autoNavigateToFocusedRow property is enabled. In the UI, users can click a row to focus it. The focused row is saved in the DataGrid's state.
You can use the onFocusedRowChanging or onFocusedRowChanged property to specify a custom function that is executed before or after a row is focused.
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
import React, { useCallback, useState } from 'react';
import {
DataGrid, Column, Paging, DataGridTypes, Pager,
} from 'devextreme-react/data-grid';
import { NumberBox, NumberBoxTypes } from 'devextreme-react/number-box';
import { CheckBox, CheckBoxTypes } from 'devextreme-react/check-box';
import 'devextreme/data/odata/store';
const focusedRowKeyLabel = { 'aria-label': 'Focused Row Key' };
const dataSourceOptions = {
store: {
type: 'odata' as const,
version: 2,
key: 'Task_ID',
url: 'https://js.devexpress.com/Demos/DevAV/odata/Tasks',
},
expand: 'ResponsibleEmployee',
select: [
'Task_ID',
'Task_Subject',
'Task_Start_Date',
'Task_Status',
'Task_Description',
'Task_Completion',
'ResponsibleEmployee/Employee_Full_Name',
],
};
const App = () => {
const [taskSubject, setTaskSubject] = useState('');
const [taskDetails, setTaskDetails] = useState('');
const [taskStatus, setTaskStatus] = useState('');
const [taskProgress, setTaskProgress] = useState('');
const [focusedRowKey, setFocusedRowKey] = useState(117);
const [autoNavigateToFocusedRow, setAutoNavigateToFocusedRow] = useState(true);
const onTaskIdChanged = useCallback((e: NumberBoxTypes.ValueChangedEvent) => {
if (e.event && e.value > 0) {
setFocusedRowKey(e.value);
}
}, []);
const onFocusedRowChanging = useCallback(async(e: DataGridTypes.FocusedRowChangingEvent) => {
const rowsCount = e.component.getVisibleRows().length;
const pageCount = e.component.pageCount();
const pageIndex = e.component.pageIndex();
const event = e?.event as any;
const key = event.key;
if (key && e.prevRowIndex === e.newRowIndex) {
if (e.newRowIndex === rowsCount - 1 && pageIndex < pageCount - 1) {
await e.component.pageIndex(pageIndex + 1);
e.component.option('focusedRowIndex', 0);
} else if (e.newRowIndex === 0 && pageIndex > 0) {
await e.component.pageIndex(pageIndex - 1);
e.component.option('focusedRowIndex', rowsCount - 1);
}
}
}, []);
const onFocusedRowChanged = useCallback((e: DataGridTypes.FocusedRowChangedEvent) => {
const data = e.row.data;
const progress = data.Task_Completion ? `${data.Task_Completion}%` : '';
setTaskSubject(data.Task_Subject);
setTaskDetails(data.Task_Description);
setTaskStatus(data.Task_Status);
setTaskProgress(progress);
setFocusedRowKey(e.component.option('focusedRowKey'));
}, []);
const onAutoNavigateToFocusedRowChanged = useCallback((e: CheckBoxTypes.ValueChangedEvent) => {
setAutoNavigateToFocusedRow(e.value);
}, []);
return (
<div>
<DataGrid
id="gridContainer"
dataSource={dataSourceOptions}
focusedRowEnabled={true}
focusedRowKey={focusedRowKey}
autoNavigateToFocusedRow={autoNavigateToFocusedRow}
onFocusedRowChanging={onFocusedRowChanging}
onFocusedRowChanged={onFocusedRowChanged}
showBorders={true}
>
<Paging defaultPageSize={10} />
<Pager visible={true} />
<Column
dataField="Task_ID"
width={80} />
<Column
caption="Start Date"
dataField="Task_Start_Date"
dataType="date" />
<Column
caption="Assigned To"
dataField="ResponsibleEmployee.Employee_Full_Name"
dataType="date"
allowSorting={false}
/>
<Column
caption="Subject"
dataField="Task_Subject"
width={350} />
<Column
caption="Status"
dataField="Task_Status" />
</DataGrid>
<div className="task-info">
<div className="info">
<div id="taskSubject">{taskSubject}</div>
<p id="taskDetails" dangerouslySetInnerHTML={{ __html: taskDetails }}></p>
</div>
<div className="progress">
<span id="taskStatus">{taskStatus}</span>
<span id="taskProgress">{taskProgress}</span>
</div>
</div>
<div className="options">
<div className="caption">Options</div>
<div className="options-container">
<div className="option">
<span>Focused Row Key </span>
<NumberBox
id="taskId"
min={1}
max={183}
step={0}
value={focusedRowKey}
inputAttr={focusedRowKeyLabel}
onValueChanged={onTaskIdChanged}>
</NumberBox>
</div>
<div className="option">
<CheckBox
text="Auto Navigate To Focused Row"
value={autoNavigateToFocusedRow}
onValueChanged={onAutoNavigateToFocusedRowChanged}>
</CheckBox>
</div>
</div>
</div>
</div>
);
};
export default App;
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
In this demo, the row with the 117
key is focused initially. You can specify the focusedRowKey
and autoNavigateToFocusedRow
properties via the input field and the checkbox below the DataGrid.