Skip to Content
0
Former Member
Jun 22, 2016 at 07:38 AM

deletion of single row in sap ui5

393 Views

hi experts,

i have created rows dynamically and each row contains a delete button, if i click on that delete button the row should be deleted

please help me

my view.xml

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"

xmlns="sap.m" controllerName="z_adding_rows.Main" xmlns:html="http://www.w3.org/1999/xhtml">

<Page title="Title">

<content>

<Table id="idProductsTable" mode="SingleSelectMaster"

selectionChange="onSelectionChange" items="{/}">

<columns>

<Column width="45%">

<Label text="First Name" />

</Column>

<Column width="45%">

<Label text="Last Name" />

</Column>

<Column width="10%">

<Label />

</Column>

</columns>

<items>

<ColumnListItem>

<cells>

<Input value="{FirstName}" />

<Input value="{LastName}" />

<Button text="Delete" press="onDelete"/>

</cells>

</ColumnListItem>

</items>

</Table>

<Button text="Add Row" press="onPress" />

</content>

</Page>

</core:View>

my controller.js

sap.ui.controller("z_adding_rows.Main", {

onInit: function(oEvent) {

var dataObject = [{

FirstName: "Madhu",

LastName: "Sudhan"

}];

var oModel = new sap.ui.model.json.JSONModel();

oModel.setData(dataObject);

sap.ui.getCore().setModel(oModel);

},

onPress: function(oEvent){

var oTable = this.getView().byId("idProductsTable");

var oModel = oTable.getModel().getProperty("/");

var nObject = {FirstName:"", LastName:""};

oModel.push(nObject);

oTable.getModel().setProperty("/", oModel);

},

onSelectionChange: function(oEvent) {

var oSelectedItem = oEvent.getParameter("listItem");

var oModel = oSelectedItem.getBindingContext().getObject();

alert(JSON.stringify(oModel));

},

onDelete : function(){

sap.m.MessageBox.show(

"Are you sure you want to delete this item", {

icon: sap.m.MessageBox.Icon.WARNING,

title: "Delete item",

actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],

onClose: function(oAction) {

if(oAction==="YES"){

}else{

}

}

}

);

}

});