Skip to content

Commit 2fa8fe7

Browse files
Merge pull request #1930 from telerik/new-kb-listview-scheduler-drag-and-drop-189f2b44512d4ae6b584309af7c98057
docs(scheduler): add new kb article listview-scheduler-drag-and-drop
2 parents b87f5e5 + 050c8ec commit 2fa8fe7

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import * as React from 'react';
2+
import * as ReactDOM from 'react-dom';
3+
import {
4+
Scheduler,
5+
WeekView,
6+
MonthView,
7+
} from '@progress/kendo-react-scheduler';
8+
import { ListView, ListViewItemProps } from '@progress/kendo-react-listview';
9+
10+
import { Grid, GridColumn } from '@progress/kendo-react-grid';
11+
12+
import gridData from './data.js';
13+
14+
const handleDragOver = (e) => {
15+
e.preventDefault();
16+
};
17+
18+
const App = () => {
19+
const MyScheduler = React.useRef();
20+
const refData = React.useRef();
21+
const refDragItem = React.useRef();
22+
const [data, setData] = React.useState([]);
23+
24+
refData.current = data;
25+
refDragItem.current = null;
26+
27+
const handleDropItem = React.useCallback((e) => {
28+
let start = e.target.getAttribute('data-slot-start');
29+
let end = e.target.getAttribute('data-slot-end');
30+
let startDate = new Date(parseInt(start));
31+
let endDate = new Date(parseInt(end));
32+
33+
let newEvent = {
34+
id: refDragItem.current.taskID,
35+
title: refDragItem.current.title,
36+
StartTimezone: null,
37+
start: startDate,
38+
end: endDate,
39+
};
40+
const newData = [newEvent, ...refData.current];
41+
refData.current = newData;
42+
setData(newData);
43+
}, []);
44+
45+
React.useEffect(() => {
46+
let schedulerElement = MyScheduler.current.element;
47+
schedulerElement.addEventListener('drop', handleDropItem);
48+
schedulerElement.addEventListener('dragover', handleDragOver);
49+
return () => {
50+
schedulerElement.removeEventListener('drop', handleDropItem);
51+
schedulerElement.removeEventListener('dragover', handleDragOver);
52+
};
53+
}, []);
54+
55+
const MyItemRender = (props) => {
56+
let item = props.dataItem;
57+
return (
58+
<div
59+
draggable={true}
60+
className="k-listview-item"
61+
onDragStart={() => {
62+
refDragItem.current = props.dataItem;
63+
}}
64+
style={{ padding: 10, borderBottom: '1px solid lightgrey' }}
65+
>
66+
{item.title}
67+
</div>
68+
);
69+
};
70+
return (
71+
<>
72+
<Scheduler
73+
data={data}
74+
defaultDate={new Date('2013/6/13')}
75+
ref={MyScheduler}
76+
>
77+
<WeekView showWorkHours={false} />
78+
<MonthView />
79+
</Scheduler>
80+
<hr />
81+
<ListView
82+
data={gridData}
83+
item={MyItemRender}
84+
style={{ width: '100%', height: 600 }}
85+
/>
86+
</>
87+
);
88+
};
89+
90+
ReactDOM.render(<App />, document.querySelector('my-app'));
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Drag and Drop Items from KendoReact ListView to KendoReact Scheduler
3+
description: Learn how to enable drag and drop functionality between KendoReact ListView and Scheduler components.
4+
type: how-to
5+
page_title: How to Enable Drag and Drop between KendoReact ListView and Scheduler
6+
slug: drag-drop-kendoreact-listview-scheduler
7+
tags: react, kendoReact, drag and drop, ListView, Scheduler
8+
res_type: kb
9+
---
10+
11+
## Environment
12+
13+
| Property | Value |
14+
| --- | --- |
15+
| Product | KendoReact |
16+
| Version | 7.0.2|
17+
18+
## Description
19+
20+
Looking for a drag and drop between KendoReact ListView and KendoReact Scheduler. I want to transfer items from the ListView to the Scheduler.
21+
22+
## Solution
23+
24+
To enable drag and drop functionality between a KendoReact ListView and a KendoReact Scheduler, follow these steps:
25+
26+
1. Render a custom ListView item by using the [`item`](https://www.telerik.com/kendo-react-ui/components/listview/api/ListViewProps/#toc-item) prop. This allows you to make the row draggable and obtain the currently dragged item.
27+
1. Add an `onDropEvent` to the Scheduler container using the [component ref](https://react.dev/reference/react/useRef).
28+
1. When the user drops an item, add it to the Scheduler data by updating the state.
29+
30+
{% meta id:index height:900 %}
31+
{% embed_file scheduler/dnd-from-listview/main.jsx preview %}
32+
{% embed_file shared/data.js %}
33+
{% endmeta %}
34+
35+
## Notes
36+
37+
- Make sure to install the required dependencies, such as `react-dnd`, `@progress/kendo-react-listview`, and `@progress/kendo-react-scheduler`.
38+
- Refer to the official documentation for more information on the `DragSource` and `useRef` APIs.
39+
- Adjust the code according to your specific use case and requirements.
40+
41+
## See Also
42+
43+
- [KendoReact ListView Documentation](https://www.telerik.com/kendo-react-ui/components/listview/)
44+
- [KendoReact Scheduler Documentation](https://www.telerik.com/kendo-react-ui/components/scheduler/)

0 commit comments

Comments
 (0)