The Power Drag Drop component allows you to create drag and drop user interfaces inside canvas apps and custom pages.
Here is an example of a Kanban style UI built using the PowerDragDrop component on top of Microsoft Dataverse.
Note: Phone layout canvas apps are not supported due to the CSS transformations they apply - instead, create a responsive tablet canvas app.
Video demo: https://youtu.be/mlrg0OfF4e8
Follow these steps to quickly get up and running with the Power Drag Drop component.
The Power Drag Drop component requires there to be a single master zone per group of items being dragged/dropped. For example, if you had a list of tasks that you wanted to drag between different Kanban lanes, you would have only a single master zone, and then a separate child zone for each lane.
Add a button to your canvas, and inside the OnSelect event add the following:
ClearCollect(
colItems,
ForAll(Sequence(10),
{
Id:Text(Value),
Name:"Item " & Value,
Zone:"zone1"
}
)
)
Click the button to create the items inside colItems
.
Select the PowerDragDrop
component on your canvas, and inside the control properties panel set the following:
colItems
zone1
zone2
On
Select the Advanced tab of the control properties panel, set the following:
"Id"
"Zone"
You should now see a list of items appear in the PowerDragDrop component.
Note: If you only see a set of empty items, check that the Name column is added to the Fields as described above.
Copy the master zone and paste it onto the canvas next to the original.
In the properties of the second zone, set the following properties:
Off
zone2
<No Value>
Go back to the original master zone and toggle the Master Zone between On
and Off
to reset it as the master.
You should now be able to drag items between the two zones:
Each time an item is dropped, the `OnDrop` event is raised.
The CurrentItems
collection on the master zone keeps track of the changes made by dragging and dropping.
If you want to reset the changes at any time (e.g. after saving the changes), you can set the InputEvent
property to a context variable such as ctxDragDropInputEvent
and set it using:
UpdateContext({ctxDragDropInputEvent: "ClearChanges" & Rand()});
If you need to force a re-render at any time due to the item data changing, you can set the InputEvent
property using:
UpdateContext({ctxDragDropInputEvent: "Reset" & Rand()});
The PowerDragDrop component has style properties such as border/background color, however if you need a more complex style, then you can use the handlebars language to create an HTML template:
<div
style="
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
display:flex;
flex-direction: column;
margin: 16px;
padding: 8px;
border-radius: 8px;
">
<div>{{Name}}</div>
<div>{{Id}}</div>
</div>
This will look similar to the following:
Note: The html will be stripped of any script elements.
If you need to add action buttons to your template, you can do so by adding a clickable element that has a class name that is prefixed with action-
followed by the name of the action (clickme
in the example below):
<div
style="
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
display:flex;
flex-direction: column;
margin: 16px;
padding: 8px;
border-radius: 8px;
">
<div>{{Name}}</div>
<button class="action-clickme">Click Me</buttom>
</div>
If you then add a label with the Text set to : $"{PowerDragDrop1.ActionName} {PowerDragDrop1.ActionItemId}"
, you will see something similar to:
Note: The clickable elements do not need to be buttons, they could be clickable links or
div
elements.
Each time an action is selected, the OnAction
event is raised.
If you want to programmatically set focus on the control you can use the following to update the context variable that is bound to the Input Event
property:
UpdateContext({ctxDragDropInputEvent:"SetFocus" & Text(Rand())})
If you need to set focus on a specific item you can use:
UpdateContext({ctxDragDropInputEvent:"FocusItem,SOME_ITEM_ID," & Text(Rand())})
Where you replace SOME_ITEM_ID
with the Id that is provided in the column designated by the IdColumn
.