Skip to Content

SAPUI5 Delete Multiple Rows (sap.m.table)

Dear All,

I am working on SAPUI5 Table, I have created a functionality to delete selected rows from the table, but when I select to delete more then one rows, it is deleting wrong rows, although first selected row is deleted correctly, nut others are not.
Please review my code and advise,

fDeleteRow: function(oEvent) {
                    // Here Calling the table from view
		var oTable = this.getView().byId("tbl");
                    // Getting the table Model
		var data = oTable.getModel();
                  // getting selected Row COunt,
	var selRowCount = oTable._oSelection.aSelectedIndices.length;
		var Flag = false;
		for (var i = 0; i < selRowCount; i++) {
		var rowNum = oTable._oSelection.aSelectedIndices[i];
		data.oData.splice(rowNum, 1);
		data.oData.refresh();
		Flag = true;
			}
			if (Flag) {
			var oModelJson = new sap.ui.model.json.JSONModel();
			oModelJson.setData(data.oData);
			oTable.unbindColumns();
			oTable.unbindRows();
			oTable.setModel(oModelJson);
			oTable.bindRows("/");
			
			}


		}

Thanks,

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 24 at 06:38 PM

    make sure the selected index are sorted, then delete from big one

    example

    1,3,5 are selected index, then you delete in this sequence 5,3,1

    Add comment
    10|10000 characters needed characters exceeded