You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: components/treeview/drag-drop.md
+246-9Lines changed: 246 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -12,11 +12,15 @@ position: 11
12
12
13
13
The Drag and Drop functionality for the TreeView allows you to move a node or multitude of nodes between different parents in the same treeview or between different Telerik TreeView instances.
14
14
15
-
This article will be divided in the following sections:
15
+
This article is divided in the following sections:
16
16
17
17
*[Basics](#basics)
18
-
*[OnDrop Event](#ondrop-event)
18
+
*[`OnDragStart` Event](#ondragstart-event)
19
+
*[`OnDrag` Event](#ondrag-event)
20
+
*[`OnDrop` Event](#ondrop-event)
21
+
*[`OnDragEnd` Event](#ondragend-event)
19
22
*[Examples](#examples)
23
+
*[Events Example](#events-example)
20
24
*[Drag and Drop between TreeView, Grid, TreeList and Scheduler](#drag-and-drop-between-treeview-grid-treelist-and-scheduler)
21
25
*[Flat Data](#flat-data)
22
26
*[Hierarchical Data](#hierarchical-data)
@@ -28,12 +32,43 @@ To enable the Drag and Drop functionality:
28
32
29
33
1. Set the `Draggable` parameter of the `<TelerikTreeView>` to `true`
30
34
31
-
1. Use the `OnDrop` event to handle the drag and drop operations and modify the data source as per your business logic.
35
+
1. Use the Drag events to handle the drag and drop operations and modify the data source as per your business logic.
32
36
37
+
## OnDragStart Event
38
+
39
+
The `OnDragStart` event fires when the user starts dragging a node. It provides details for the dragged item and allows you to cancel the event.
40
+
41
+
### Event Arguments
42
+
43
+
The `OnDragStart` event handler receives as an argument an object of type `TreeViewDragStartEventArgs` that contains:
44
+
45
+
| Parameter | Type | Description |
46
+
| --- | --- | --- |
47
+
|`Item`|`object`| Represents the dragged row. You can cast this object to your model class. |
48
+
|`IsCancelled`|`bool`| Whether the event is to be prevented. |
49
+
50
+
## OnDrag Event
51
+
52
+
The `OnDrag` event fires continuously while the user is dragging a node.
53
+
54
+
### Event Arguments
55
+
56
+
The `OnDrag` event handler receives as an argument an object of type `TreeViewDragEventArgs` that contains:
57
+
58
+
| Parameter | Type | Description |
59
+
| --- | --- | --- |
60
+
|`Item`|`object`| Represents the dragged row. You can cast this object to your model class. |
61
+
|`DestinationItem`|`object`| Represents the row over which the `Item` is. You can cast this object to your model class. |
62
+
|`DestinationTreeView`|`object`| The reference of the TreeView in which the `Item` is dropped. |
63
+
|`DestinationIndex`|`string`| The index in the target component where the drop will happen. |
64
+
|`DestinationComponentId`|`string`| The `Id` of the target component in which the drop will happen. |
65
+
|`DropPosition`|`enum`| Its members allow you to determine the exact position of the dropped item relative to the position of the `DestinationItem`. |
66
+
|`PageX`|`double`| Represents the X coordinate of the mouse. |
67
+
|`PageY`|`double`| Represents the Y coordinate of the mouse. |
33
68
34
69
## OnDrop Event
35
70
36
-
The `OnDrop` event fires when the user drops a node into a new location. It allows you to manipulate your data collection based on where the user dropped the element.
71
+
The `OnDrop` event fires when the user drops a node to a new location. It is triggered only if the new location is a Telerik component. The event allows you to manipulate your data collection based on where the user dropped the element.
37
72
38
73
### Event Arguments
39
74
@@ -49,13 +84,215 @@ The `OnDrop` event provides an object of type `TreeViewDropEventArgs` to its eve
49
84
|`DestinationIndex`|`string`| The index where the drop will happen in the second component. |
50
85
|`DestinationComponentId`|`string`| The `Id` of the second component in which the drop will happen. |
51
86
87
+
## OnDragEnd Event
88
+
89
+
The `OnDragEnd` event fires when a drag operation ends. The event is triggered after `OnDrop` and unlike it, `OnDragEnd` will fire even if the drop location is not a Telerik component. In this case, the non-aplicable event arguments will be null.
90
+
91
+
### Event Arguments
92
+
93
+
The `OnDragEnd` event handler receives as an argument an object of type `TreeViewDragEndEventArgs` that contains:
94
+
95
+
| Parameter | Type | Description |
96
+
| --- | --- | --- |
97
+
|`DestinationItem`|`object`| Represents the row over which the `Item` is. You can cast this object to your model class. |
98
+
|`DestinationTreeView`|`object`| The reference of the TreeView in which the `Item` is dropped. |
99
+
|`DestinationIndex`|`string`| The index in the target component where the drop will happen. |
100
+
|`DestinationComponentId`|`string`| The `Id` of the target component in which the drop will happen. |
101
+
|`DropPosition`|`enum`| Its members allow you to determine the exact position of the dropped item relative to the position of the `DestinationItem`. |
102
+
52
103
## Examples
53
104
105
+
*[Events Example](#events-example)
54
106
*[Drag and Drop between TreeView, Grid, TreeList and Scheduler](#drag-and-drop-between-treeview-grid-treelist-and-scheduler)
55
107
*[Flat Data](#flat-data)
56
108
*[Hierarchical Data](#hierarchical-data)
57
109
*[Between Different TreeViews](#between-different-treeviews)
if (destinationItem?.Parent == null || item == null)
262
+
{
263
+
return false;
264
+
}
265
+
else if (destinationItem.Parent?.Equals(item.Id) == true)
266
+
{
267
+
return true;
268
+
}
269
+
270
+
var parentDestinationItem = Data.FirstOrDefault(e => e.Id.Equals(destinationItem.Parent));
271
+
272
+
return IsChild(item, parentDestinationItem);
273
+
}
274
+
275
+
private void LoadData()
276
+
{
277
+
Data = new List<TreeItem>()
278
+
{
279
+
new TreeItem(1, null, "Documents", SvgIcon.Folder, true),
280
+
new TreeItem(2, 1, "report.xlsx", SvgIcon.FileExcel, false),
281
+
new TreeItem(3, 1, "status.docx", SvgIcon.FileWord, false),
282
+
new TreeItem(4, 1, "conferences.xlsx", SvgIcon.FileExcel, false),
283
+
new TreeItem(5, 1, "performance.pdf", SvgIcon.FilePdf, false),
284
+
new TreeItem(6, null, "Pictures", SvgIcon.Folder, true),
285
+
new TreeItem(7, 6, "Camera Roll", SvgIcon.Folder, true),
286
+
new TreeItem(8, 7, "team.png", SvgIcon.FileImage, false),
287
+
new TreeItem(9, 7, "team-building.png", SvgIcon.FileImage, false),
288
+
new TreeItem(10, 7, "friends.png", SvgIcon.FileImage, false),
289
+
};
290
+
ExpandedItems = Data.ToList();
291
+
}
292
+
293
+
}
294
+
````
295
+
59
296
### Drag and Drop between TreeView, Grid, TreeList and Scheduler
60
297
61
298
The functionality allows dragging items between TreeView, [Grid]({%slug grid-drag-drop-overview%}), [TreeList]({%slug treelist-drag-drop-overview%}) and [Scheduler]({%slug scheduler-overview%}). To achieve it, set the `Draggable`/`RowDraggable` parameter, and implement it through an event - `OnDrop`/`OnRowDrop`.
@@ -99,12 +336,12 @@ The functionality allows dragging items between TreeView, [Grid]({%slug grid-dra
99
336
</TelerikTreeView>
100
337
101
338
@code {
102
-
public List<Person> GridData { get; set; }
103
-
public TelerikGrid<Person> GridRef { get; set; }
339
+
private List<Person> GridData { get; set; }
340
+
private TelerikGrid<Person> GridRef { get; set; }
104
341
105
-
public TelerikTreeView TreeRef { get; set; }
106
-
public TreeViewObservableFlatDataService TreeService { get; set; }
107
-
public ObservableCollection<BaseFlatItem> TreeData { get; set; }
Copy file name to clipboardExpand all lines: components/treeview/events.md
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@ This article explains the events available in the Telerik TreeView for Blazor:
20
20
*[OnItemDoubleClick](#onitemdoubleclick)
21
21
*[OnItemRender](#onitemrender)
22
22
*[SelectedItemsChanged](#selecteditemschanged)
23
+
*[Drag Events](#drag-events)
23
24
24
25
## CheckedItemsChanged
25
26
@@ -78,6 +79,17 @@ The event handler receives as an argument an `TreeViewItemRenderEventArgs` objec
78
79
79
80
The `SelectedItemsChanged` event fires when the [selection]({%slug treeview-selection-overview%}) is enabled and the user clicks on a new item.
80
81
82
+
## Drag Events
83
+
84
+
The TreeView implements the Drag and Drop functionality through the following drag events:
85
+
86
+
* The `OnDragStart` event fires when the user starts dragging a node.
87
+
* The `OnDrag` event fires continuously while a node is being dragged by the user.
88
+
* The `OnDrop` event fires when the user drops a node into a new location. The event fires only if the new location is a Telerik component.
89
+
* The `OnDragEnd` event fires when a drag operation ends. Unlike the `OnDrop` event, `OnDragEnd` will fire even if the new location is not a Telerik component.
90
+
91
+
For more details and examples, see the [Treeview Drag and Drop]({%slug treeview-drag-drop-overview%}) article.
Copy file name to clipboardExpand all lines: components/treeview/overview.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -135,6 +135,7 @@ The following table lists TreeView parameters, which are not related to other fe
135
135
| --- | --- | --- |
136
136
|`Class`|`string`| The additional CSS class that will be rendered on the `div.k-treeview` element. Use it to apply custom styles or [override the theme]({%slug themes-override%}). |
137
137
|`Size`|`string` <br /> `"md"`| Affects the TreeView layout, for example the amount of space between items. The possible valid values are `"lg"` (large), `"md"` (medium) and `"sm"` (small). For easier setting, use the predefined string properties in class [`Telerik.Blazor.ThemeConstants.TreeView.Size`](/blazor-ui/api/Telerik.Blazor.ThemeConstants.TreeView.Size). |
138
+
|`DragThrottleInterval`|`int` <br /> (`0`) | The milliseconds between each firing of the `OnDrag` event during the dragging operations. |
0 commit comments