In this tutorial I will explain how you can implement drag and drop in SAPUI5. We’ll create a list from which we can drag the list items into a table. The details of the list item will be added as a row in the table. For a demo, look at the following video:

JQuery UI provides easy functionalities to implement drag and drop. To access these functionalities we need to import these libraries to our project. To to so, add the following code to your index page:

  jQuery(function() {
  var app = new sap.m.App();
  var page = sap.ui.view({id:"iddetail1", viewName:"sapui5draganddrop.detail", type:sap.ui.core.mvc.ViewType.XML});

My code in my view is the following:

  <List id="dragableList" width="200px" class="dragList" items="{materials>/}">
            <StandardListItem title="{materials>description}" />
  <Table id="dropableTable" inset="false" width="500px" class="table">
            <Column hAlign="Center">
                 <Text text="Material" />
       <Column hAlign="Center">
            <Text text="Vendor" />

In an HBox I added the list and the table. Make sure you give both the list and the table an ID, we need this in the controller.

In our controller, we will implement our code in the onInit() function. First part is general coding where I define my variables and set my model:

onInit: function() {
  var oSortableList = this.getView().byId("dragableList");
  var listId = oSortableList.getId();
  var listUlId = listId + "-listUl";
  var materialModel = new sap.ui.model.json.JSONModel();
  var oDropableTable = this.getView().byId("dropableTable");
  var tableId = oDropableTable.getId();
  var materials = [
  {id: "0", description: "material 1", vendor: "vendor 1"},
  {id: "1", description: "material 2", vendor: "vendor 1"},
  {id: "2", description: "material 3", vendor: "vendor 2"},
  {id: "3", description: "material 4", vendor: "vendor 2"}
  this.getView().setModel(materialModel, "materials");

The first step we need to do is make the list drag-able, you can do this with the following code:

oSortableList.onAfterRendering = function() {
         if (sap.m.List.prototype.onAfterRendering) {
  $("#"+listUlId+" li").draggable({
         helper: "clone"

When you implemented this code you’ll see that you can drag the list items, but when you drop them, nothing happens. For that we need to make our table drop-able:

oDropableTable.onAfterRendering = function() {
         if (sap.m.Table.prototype.onAfterRendering) {
       drop: function( event, ui ) {
       var listElementId =;
       var draggedElement = sap.ui.getCore().byId(listElementId);
       var oPath = draggedElement.getBindingContext("materials").getPath();
       var split = oPath.split("/");
   var i = split[1];
   var materialData = materialModel.getData();
          new sap.m.ColumnListItem({
          cells: [
                 new sap.m.Text({text: materialData[i].description}),
                 new sap.m.Text({text: materialData[i].vendor})

When the drop event is triggered, we can access the ID of our list item which we have dropped on the table. With this ID we can access the list item, retrieve the binding context and the path. And with this path we can read out the correct line from our material data. We then add this data as an item to our table.

And that’s how easy it is to implement drag and drop functionalities in SAPUI5.

Remark: it does seem that the two elements need to be in the same element (in this case the HBox). I tested to see if it is for example possible to drag in a splitapp from the master view to the detail view but this doesn’t seem to be possible. So there are some limitations.

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Neil Gardiner

    Hi Stephanie,

    Are you able to add code snippets rather than screen shots? This makes it easier for others who wish to C&P the code if they want to try the solution for themselves.




Leave a Reply