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:
<mvc:View controllerName="DragNDrop.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m" xmlns:dnd="sap.ui.core.dnd" xmlns:control="DragNDrop.controls">
<App>
<pages>
<Page title="{i18n>title}" titleAlignment="Center">
<content>
<Table items="{EmpData>/content}">
<dragDropConfig>
<dnd:DragInfo sourceAggregation="items"/>
</dragDropConfig>
<columns>
<Column>
<header>
<Text text="Emp Name"/>
</header>
</Column>
<Column>
<header>
<Text text="Emp ID"/>
</header>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{EmpData>Name}"/>
<Text text="{EmpData>ID}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</content>
<footer>
<Bar>
<contentMiddle>
<control:DeleteButton id="deleteButtonId" text="Delete" type="Reject" icon="sap-icon://delete" width="30%">
<control:dragDropConfig>
<dnd:DropInfo drop="onDrop"/>
</control:dragDropConfig>
</control:DeleteButton>
</contentMiddle>
</Bar>
</footer>
</Page>
sap.ui.define([
"sap/m/Button"
], function (Button) {
"use strict";
return Button.extend("DragNDrop.controls.DeleteButton", {
metadata: {
dnd: {
droppable: true
}
},
renderer: {}
});
});
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/m/MessageBox"
], function(Controller,MessageBox) {
"use strict";
return Controller.extend("DragNDrop.controller.View1", {
inIt:function(){},
onDrop:function(oEvent){
var bindingContext=parseInt(oEvent.getParameters('dragSession').draggedControl.getBindingContextPath().split('/')[2]);
var oEmpModel=this.getOwnerComponent().getModel("EmpData");
var oEmpModelData=oEmpModel.getData().content;
oEmpModelData.splice(bindingContext,1);
oEmpModel.setProperty('/content',oEmpModelData);
oEmpModel.refresh();
MessageBox.success("Employee record deleted!");
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |