Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Hello UI5 Experts,

This weekend i felt like exploring the Drag and Drop capability of UI5 controls that has been made available for UI5 version greater than 1.56. Drag and drop is a very intuitive user experience and may come up as a requirement any time in one of our projects. While exploring a few resources, i came across this great post which seemed to serve my purpose perfectly. Here is the link to it:


To my dismay, the end product was not working. So i took it upon myself to complete this and here i am presenting the same to you.


Here we have a list of employee records and instead of selecting a record and hitting the Delete Button, here we are providing the capability to drag the record on the delete button to perform the same function.


Initial Screen


Now i will drag and drop the second record on the Delete button it should disappear from the table.


Dragging second record to the delete button


Voila! Record has been deleted


So let us go a bit deeper and see what's really happening here.


First we need to specify the "DragInfo" for the Table control as shown below. The source aggregation is "items" as we will be looking to drag a ColumnListItem from the Table.

<mvc:View controllerName="DragNDrop.controller.View1" xmlns:html="" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m" xmlns:dnd="sap.ui.core.dnd" xmlns:control="DragNDrop.controls">
<Page title="{i18n>title}" titleAlignment="Center">
<Table items="{EmpData>/content}">
<dnd:DragInfo sourceAggregation="items"/>
<Text text="Emp Name"/>
<Text text="Emp ID"/>
<Text text="{EmpData>Name}"/>
<Text text="{EmpData>ID}"/>


Next we specify the "DropInfo" of the Delete button as shown in the below code:

<control:DeleteButton id="deleteButtonId" text="Delete" type="Reject" icon="sap-icon://delete" width="30%">
<dnd:DropInfo drop="onDrop"/>


Now if you notice, my Button is a custom button control here. This is because for a Button control, by default the "droppable" meta-data property is set to false. So we need to change that to true in order to be able to drop items into the button. Below code snippet shows how the meta-data is updated.

], function (Button) {
"use strict";
return Button.extend("DragNDrop.controls.DeleteButton", {
metadata: {
dnd: {
droppable: true
renderer: {}

Once a item is "dropped" in the above Button, the "drop" event is triggered which calls the below function in the controller. This function gets the context of the item that was dragged w.r.t the table model and deletes the entry from the model.
], function(Controller,MessageBox) {
"use strict";

return Controller.extend("DragNDrop.controller.View1", {
var bindingContext=parseInt(oEvent.getParameters('dragSession').draggedControl.getBindingContextPath().split('/')[2]);
var oEmpModel=this.getOwnerComponent().getModel("EmpData");
var oEmpModelData=oEmpModel.getData().content;

MessageBox.success("Employee record deleted!");


Hope this blog helps you implement the drag-drop functionality in your future projects. Below are a few URLs that you may refer to for more information:




1 Comment
Labels in this area