Skip to Content

deletion of single row in sap ui5

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{

}

}

}

);

}

});

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jun 22, 2016 at 08:02 AM

    Hi Madhu,

    Will this sample help? JS Bin - Collaborative JavaScript Debugging

    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 22, 2016 at 07:54 AM
    onDelete: function(oEvent) { var oModel = this.getView().getModel(); var sPath = oEvent.getSource().getBindingContext().sPath;

    oModel.remove(sPath, { success: function() { sap.m.MessageToast.show("Delete item"); }, error: function() { sap.m.MessageToast.show("Item deletion failed"); } }); }
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.