import React, { useCallback, useState } from 'react';
import Scheduler, { AppointmentDragging } from 'devextreme-react/scheduler';
import type { SchedulerTypes } from 'devextreme-react/scheduler';
import Draggable from 'devextreme-react/draggable';
import type { DraggableTypes } from 'devextreme-react/draggable';
import ScrollView from 'devextreme-react/scroll-view';
import { appointments as defaultAppointments, tasks as defaultTasks } from './data.ts';
import type { Task } from './data.ts';
const currentDate = new Date(2021, 3, 26);
const views: SchedulerTypes.Properties['views'] = [{ type: 'day', intervalCount: 3 }];
const draggingGroupName = 'appointmentsGroup';
const onListDragStart = (e: DraggableTypes.DragStartEvent) => {
e.cancel = true;
};
const onItemDragStart = (e: DraggableTypes.DragStartEvent) => {
e.itemData = e.fromData;
};
const onItemDragEnd = (e: DraggableTypes.DragEndEvent) => {
if (e.toData) {
e.cancel = true;
}
};
const App = () => {
const [state, setState] = useState({
tasks: defaultTasks, appointments: defaultAppointments,
});
const onAppointmentRemove = useCallback((e: SchedulerTypes.AppointmentDraggingRemoveEvent) => {
setState((currentState: { appointments: SchedulerTypes.Appointment[]; tasks: Task[]; }) => {
const { appointments, tasks } = currentState;
const index = appointments.indexOf(e.itemData);
if (index >= 0) {
tasks.push(e.itemData);
appointments.splice(index, 1);
}
return { appointments: [...appointments], tasks: [...tasks] };
});
}, []);
const onAppointmentAdd = useCallback((e: SchedulerTypes.AppointmentDraggingAddEvent) => {
setState((currentState: { appointments: SchedulerTypes.Appointment[]; tasks: Task[]; }) => {
const { appointments, tasks } = currentState;
const index = tasks.indexOf(e.fromData);
if (index >= 0) {
tasks.splice(index, 1);
appointments.push(e.itemData);
}
return { appointments: [...appointments], tasks: [...tasks] };
});
}, []);
return (
<>
<ScrollView id="scroll">
<Draggable
id="list"
data="dropArea"
group={draggingGroupName}
onDragStart={onListDragStart}>
{state.tasks.map((task) => (
<Draggable
key={task.text}
className="item dx-card"
clone={true}
group={draggingGroupName}
data={task}
onDragStart={onItemDragStart}
onDragEnd={onItemDragEnd}
>
{task.text}
</Draggable>
))}
</Draggable>
</ScrollView>
<Scheduler
id="scheduler"
timeZone="America/Los_Angeles"
dataSource={state.appointments}
views={views}
defaultCurrentDate={currentDate}
height={600}
startDayHour={9}
editing={true}
>
<AppointmentDragging
group={draggingGroupName}
onRemove={onAppointmentRemove as any}
onAdd={onAppointmentAdd as any}
/>
</Scheduler>
</>
);
};
export default App;
import React, { useCallback, useState } from 'react';
import Scheduler, { AppointmentDragging } from 'devextreme-react/scheduler';
import Draggable from 'devextreme-react/draggable';
import ScrollView from 'devextreme-react/scroll-view';
import { appointments as defaultAppointments, tasks as defaultTasks } from './data.js';
const currentDate = new Date(2021, 3, 26);
const views = [{ type: 'day', intervalCount: 3 }];
const draggingGroupName = 'appointmentsGroup';
const onListDragStart = (e) => {
e.cancel = true;
};
const onItemDragStart = (e) => {
e.itemData = e.fromData;
};
const onItemDragEnd = (e) => {
if (e.toData) {
e.cancel = true;
}
};
const App = () => {
const [state, setState] = useState({
tasks: defaultTasks,
appointments: defaultAppointments,
});
const onAppointmentRemove = useCallback((e) => {
setState((currentState) => {
const { appointments, tasks } = currentState;
const index = appointments.indexOf(e.itemData);
if (index >= 0) {
tasks.push(e.itemData);
appointments.splice(index, 1);
}
return { appointments: [...appointments], tasks: [...tasks] };
});
}, []);
const onAppointmentAdd = useCallback((e) => {
setState((currentState) => {
const { appointments, tasks } = currentState;
const index = tasks.indexOf(e.fromData);
if (index >= 0) {
tasks.splice(index, 1);
appointments.push(e.itemData);
}
return { appointments: [...appointments], tasks: [...tasks] };
});
}, []);
return (
<>
<ScrollView id="scroll">
<Draggable
id="list"
data="dropArea"
group={draggingGroupName}
onDragStart={onListDragStart}
>
{state.tasks.map((task) => (
<Draggable
key={task.text}
className="item dx-card"
clone={true}
group={draggingGroupName}
data={task}
onDragStart={onItemDragStart}
onDragEnd={onItemDragEnd}
>
{task.text}
</Draggable>
))}
</Draggable>
</ScrollView>
<Scheduler
id="scheduler"
timeZone="America/Los_Angeles"
dataSource={state.appointments}
views={views}
defaultCurrentDate={currentDate}
height={600}
startDayHour={9}
editing={true}
>
<AppointmentDragging
group={draggingGroupName}
onRemove={onAppointmentRemove}
onAdd={onAppointmentAdd}
/>
</Scheduler>
</>
);
};
export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.tsx';
ReactDOM.render(
<App />,
document.getElementById('app'),
);
import type { SchedulerTypes } from 'devextreme-react/scheduler';
export type Task = {
text: string;
};
export const tasks: Task[] = [
{
text: 'New Brochures',
}, {
text: 'Brochure Design Review',
}, {
text: 'Upgrade Personal Computers',
}, {
text: 'Install New Router in Dev Room',
}, {
text: 'Upgrade Server Hardware',
}, {
text: 'Install New Database',
}, {
text: 'Website Re-Design Plan',
}, {
text: 'Create Icons for Website',
}, {
text: 'Submit New Website Design',
}, {
text: 'Launch New Website',
},
];
export const appointments: SchedulerTypes.Appointment[] = [
{
text: 'Book Flights to San Fran for Sales Trip',
startDate: new Date('2021-04-26T19:00:00.000Z'),
endDate: new Date('2021-04-26T20:00:00.000Z'),
allDay: true,
}, {
text: 'Approve Personal Computer Upgrade Plan',
startDate: new Date('2021-04-27T17:00:00.000Z'),
endDate: new Date('2021-04-27T18:00:00.000Z'),
}, {
text: 'Final Budget Review',
startDate: new Date('2021-04-27T19:00:00.000Z'),
endDate: new Date('2021-04-27T20:35:00.000Z'),
}, {
text: 'Approve New Online Marketing Strategy',
startDate: new Date('2021-04-28T19:00:00.000Z'),
endDate: new Date('2021-04-28T21:00:00.000Z'),
}, {
text: 'Customer Workshop',
startDate: new Date('2021-04-29T18:00:00.000Z'),
endDate: new Date('2021-04-29T19:00:00.000Z'),
allDay: true,
}, {
text: 'Prepare 2021 Marketing Plan',
startDate: new Date('2021-04-29T18:00:00.000Z'),
endDate: new Date('2021-04-29T20:30:00.000Z'),
},
];
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
ReactDOM.render(<App />, document.getElementById('app'));
export const tasks = [
{
text: 'New Brochures',
},
{
text: 'Brochure Design Review',
},
{
text: 'Upgrade Personal Computers',
},
{
text: 'Install New Router in Dev Room',
},
{
text: 'Upgrade Server Hardware',
},
{
text: 'Install New Database',
},
{
text: 'Website Re-Design Plan',
},
{
text: 'Create Icons for Website',
},
{
text: 'Submit New Website Design',
},
{
text: 'Launch New Website',
},
];
export const appointments = [
{
text: 'Book Flights to San Fran for Sales Trip',
startDate: new Date('2021-04-26T19:00:00.000Z'),
endDate: new Date('2021-04-26T20:00:00.000Z'),
allDay: true,
},
{
text: 'Approve Personal Computer Upgrade Plan',
startDate: new Date('2021-04-27T17:00:00.000Z'),
endDate: new Date('2021-04-27T18:00:00.000Z'),
},
{
text: 'Final Budget Review',
startDate: new Date('2021-04-27T19:00:00.000Z'),
endDate: new Date('2021-04-27T20:35:00.000Z'),
},
{
text: 'Approve New Online Marketing Strategy',
startDate: new Date('2021-04-28T19:00:00.000Z'),
endDate: new Date('2021-04-28T21:00:00.000Z'),
},
{
text: 'Customer Workshop',
startDate: new Date('2021-04-29T18:00:00.000Z'),
endDate: new Date('2021-04-29T19:00:00.000Z'),
allDay: true,
},
{
text: 'Prepare 2021 Marketing Plan',
startDate: new Date('2021-04-29T18:00:00.000Z'),
endDate: new Date('2021-04-29T20:30:00.000Z'),
},
];
<!DOCTYPE html>
<html lang="en">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" />
<link rel="stylesheet" type="text/css" href="./bundle.css" />
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="app"></div>
</div>
<script src="bundles/vendor/react.vendor.js"></script>
<script src="./bundle.js"></script>
</body>
</html>
#scroll,
#list {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 240px;
}
.item {
color: var(--dx-color-text);
background-color: var(--dx-component-color-bg);
box-sizing: border-box;
padding: 10px 20px;
margin-bottom: 10px;
}
#scheduler {
margin-left: 270px;
}
.dx-draggable-source {
opacity: 0.5;
}
.dx-draggable-dragging > * {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 6px 8px rgba(0, 0, 0, 0.2);
}