cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete row from a Table?

0 Kudos

Hi,

I have a table which is being populated through sap.ui.model.json.JSONModel(). I want to delete selected row from table.

Kindly suggest how to achieve this?

View Entire Topic
Qualiture
Active Contributor
0 Kudos

Hi Ash,

Simply create a button which in the onPress event removes the selected entry from your JSON model using the getIsSelected() method

0 Kudos

I have a delete link on each row of the table. On click of link it should delete  that row from table as well as JSON model?

//table

var oTable = new sap.ui.table.Table({

                              //title: "Table Example",

                              id: "Tab1",

                              selectionMode: sap.ui.table.SelectionMode.Single,

                              selectionBehavior:sap.ui.table.SelectionBehavior.RowOnly,

                              visibleRowCount: 5

 

                    });

                    //Define the columns and the control templates to be used

                    var oColumn = new sap.ui.table.Column({

                              label: new sap.ui.commons.Label({text: "Rule name"}),

                              template: new sap.ui.commons.TextView().bindProperty("text", "ruleId"),

                              sortProperty: "ruleId",

                              filterProperty: "ruleId",

                              width: "250px"

                    });

 

                    oTable.addColumn(oColumn);

                    oTable.addColumn(new sap.ui.table.Column({

                              label: new sap.ui.commons.Label({text: "Rule Effect"}),

                              template: new sap.ui.commons.TextField().bindProperty("value", "ruleEffect"),

                              sortProperty: "ruleEffect",

                              filterProperty: "ruleEffect",

                              width: "250px"

                    }));

 

                    oTable.addColumn(new sap.ui.table.Column({

                              label: new sap.ui.commons.Label({text: "Action"}),

                              template: new sap.ui.commons.Link({

                                        text: "Delete",

                                        tooltip: "Delete the rule",

                                        press: function()  {deleteRow();}}),

                                  width: "250px"

                    }));

Qualiture
Active Contributor
0 Kudos

Hi,

Just delete the current row from you model. Once it's deleted, your table immediately reflects your changes

0 Kudos

Thanks Robin, Its done.

0 Kudos

If binding is switched off, any row can be deleted by function like this:

deleteRowByIndex : function (idx) {

    if (idx >= 0) {

        $('Rowset Row:eq(' + idx + ')', this.oData).remove();

        this.checkUpdate();

    }

    return this;

}