Skip to Content

One of the most powerful interaction design pattern available to developers is Drag-and-Drop.

Drag-and-Drop allows moving, reordering and applying actions to objects. This makes it a simple and intuitive action, in line with Fiori and users’ expectations.

With SAPUI5 version 1.56, a new dragAndDrop aggregation with multiplicity 0..n is now available for every Control in UI5 and it can be used to configure complete drag-and-drop scenarios via DragInfoDropInfo or DragDropInfo without really giving it much thought!

Let’s briefly have a look at this simple but powerful drag-and-drop condiguration objects.

 

 

DragInfo can be used just to allow dragging when drop target is not known or not owned. Additional draggable checks can be done at the dragStart event and default can be prevented.

DropInfo can be used as a general drop target. Incoming data may need to be validated at the dragEnter event. Applications should just implement the drop event.

DragDropInfo can be used when the drag source and the drop target are tightly coupled and both are known. The most common use-case is enablement own aggregations.

Both DragInfo and DropInfo offers groupName property. If this property is specified, then the DropInfo object will only interact with the relevant DragInfo objects within the same group.

Let’s don’t make this attractive topic boring with long texts. Let’s see a little code snippet first.

 Enable reordering of the items inside the List
 <List items=”{/Products}”>
    <dragDropConfig>
        <dnd:DragDropInfo
            sourceAggregation=”items”
            targetAggregation=”items”
            dropPosition=”Between”
            drop=”onReorderItems”/>
    </dragDropConfig>
 </List>

 

Now let’s see Drag-and-Drop in action.

 

If you could follow all the links above that means you’ve learned already a lot. Now it is time for fun! 🥳 Yes… UI5 is not only for enterprise-ready web applications, sometimes just for jun. Let’s play a little drag-and-drop game and don’t hesitate to hack the source code if you cannot solve the puzzle.

 

Here are some useful links if you want to know more about drag-and-drop in UI5.

 

Previous post: UI5ers Buzz #31

Cahit

"Guess who I am?".charAt.call(Number, 1) + (this + "")[9] + [...[...'.....']].length + ``.substr.call(/(?:)/.constructor.name, 3) + alert.name.slice(-3);

 

To report this post you need to login first.

7 Comments

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

  1. Michelle Crapo

    I really like this blog!!!!   Examples my poor overloaded mind really appreciates the time you took to put together examples.   (Samples)

    (3) 
    1. Cahit Guerguec Post author

      I am glad to hear that you liked the samples. Actually I wanted to add more samples, like defining custom drag ghosts, transferring data between two UI5 applications… Stay tuned, I will update the post soon.

       

      (1) 
  2. Margot Wollny

    I just love your dragNdrop game 😀 I remember having it as kid as a “real” game …  again addicted to it! Still wonder how you made it in 38 drops …???

    If you would add a highscore to it, then this Web page would become quite busy 😉

    Thanks for the great work!

    (1) 
  3. Volker Buzek

    very cool shakes, generic drag’n’drop functionality!

    I almost hesitate to ask…but…how do we test that w/ OPA? Probably there’s already some documentation out there and I just might have missed it.

     

    (1) 
    1. Cahit Guerguec Post author

      Hi Volker, as you can see at the concept slides, UI5 is leveraging the native HTML Drag&Drop API.

       

      This means you can just trigger native events from the control DOM to test the complete drag&drop scenarios. So something like below probably be enough to test most of the use cases.

      function triggerEvent (control, type, options) {
          let event = new DragEvent(type, Object.assign({bubbles: true, cancelable: true}, options));
          control.getDomRef().dispatchEvent(event);
      }

       

      We also had an idea to simulate drag&drop to help keyboard handling, context menu and toolbar buttons that do the equivalent of the drag&drop actions for accessible reasons. Probably this could also be very nice syntatic sugar for testing.

      DnDSim.grab(item1).moveToBottomOf(item5).drop();
      DnDSim.drag(item2).to(item4);

      Thanks for this question now we have one more reason to have this in the framework!

      (0) 

Leave a Reply