-
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 Sortable - Kanban
The Sortable component allows users to reorder elements using drag and drop.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
import React, { useCallback, useState } from 'react';
import ScrollView from 'devextreme-react/scroll-view';
import Sortable from 'devextreme-react/sortable';
import {
tasks as taskList, employees, Employee, Task,
} from './data.ts';
function getLists(statusArray: string[], taskArray: Task[]) {
const tasksMap = taskArray.reduce((result: { [x: string]: any[]; }, task: { Task_Status: string | number; }) => {
if (result[task.Task_Status]) {
result[task.Task_Status].push(task);
} else {
result[task.Task_Status] = [task];
}
return result;
}, {});
return statusArray.map((status: string | number) => tasksMap[status]);
}
function getEmployeesMap(employeesArray: Employee[]): Record<string, string> {
return employeesArray.reduce((result, employee) => {
result[employee.ID] = employee.Name;
return result;
}, {});
}
function removeItem(array: any[], removeIdx: number) {
return array.filter((_, idx) => idx !== removeIdx);
}
function insertItem(array: any[], item, insertIdx: number) {
const newArray = [...array];
newArray.splice(insertIdx, 0, item);
return newArray;
}
function reorderItem(array: any[], fromIdx: number, toIdx: number) {
const item = array[fromIdx];
const result = removeItem(array, fromIdx);
return insertItem(result, item, toIdx);
}
const taskStatuses = ['Not Started', 'Need Assistance', 'In Progress', 'Deferred', 'Completed'];
const employeesRecord = getEmployeesMap(employees);
const Card: React.FC<{ task: Task, employeesMap: Record<string, string> }> = ({
task, employeesMap,
}) => <div className="card dx-card">
<div className={`card-priority priority-${task.Task_Priority}`}></div>
<div className="card-subject">{task.Task_Subject}</div>
<div className="card-assignee">{employeesMap[task.Task_Assigned_Employee_ID]}</div>
</div>;
const List: React.FC<{ title, index, tasks, employeesMap, onTaskDrop }> = ({
title, index, tasks, employeesMap, onTaskDrop,
}) => <div className="list">
<div className="list-title">{title}</div>
<ScrollView
className="scrollable-list"
direction="vertical"
showScrollbar="always">
<Sortable
className="sortable-cards"
group="cardsGroup"
data={index}
onReorder={onTaskDrop}
onAdd={onTaskDrop}>
{tasks.map((task) => <Card
key={task.Task_ID}
task={task}
employeesMap={employeesMap}>
</Card>)}
</Sortable>
</ScrollView>
</div>;
function App() {
const [statuses, setStatuses] = useState(taskStatuses);
const [lists, setLists] = useState(getLists(taskStatuses, taskList));
const onListReorder = useCallback(({ fromIndex, toIndex }) => {
setLists((state) => reorderItem(state, fromIndex, toIndex));
setStatuses((state) => reorderItem(state, fromIndex, toIndex));
}, []);
const onTaskDrop = useCallback(
({
fromData, toData, fromIndex, toIndex,
}) => {
const updatedLists = [...lists];
const item = updatedLists[fromData][fromIndex];
updatedLists[fromData] = removeItem(updatedLists[fromData], fromIndex);
updatedLists[toData] = insertItem(updatedLists[toData], item, toIndex);
setLists(updatedLists);
},
[lists],
);
return (
<div id="kanban">
<ScrollView
className="scrollable-board"
direction="horizontal"
showScrollbar="always">
<Sortable
className="sortable-lists"
itemOrientation="horizontal"
handle=".list-title"
onReorder={onListReorder}>
{lists.map((tasks, listIndex: string | number) => {
const status = statuses[listIndex];
return <List
key={status}
title={status}
index={listIndex}
tasks={tasks}
employeesMap={employeesRecord}
onTaskDrop={onTaskDrop}>
</List>;
})}
</Sortable>
</ScrollView>
</div>
);
}
export default App;
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
In this demo, two different Sortables (identified by the class
attribute) are used:
-
sortable-lists
This Sortable allows users to reorder card lists. It nests<div>
elements that represent the lists. The handle property specifies that lists can be dragged by their titles. To correctly animate items being reordered, Sortable requires the item orientation. The itemOrientation property is set to "horizontal" because card lists are orientated horizontally. -
sortable-cards
This Sortable allows users to reorder cards. It nests<div>
elements that represent all cards in a specific list. All Sortables are added to the same group to allow users to move cards between lists.
When a user moves an element in the UI, you need to move the corresponding data object in code. Handle events to implement this functionality. These events depend on your use-case. In this demo, we handle the onDragStart and onAdd events for Sortable with the sortable-lists
class and the onReorder event for both Sortables.
In addition to Sortable, this kanban board implementation uses the ScrollView component. The component's instance with the scrollable-board
class allows you to scroll the board left to right. The component's instance with the scrollable-list
class makes lists scrollable.