cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete a table row using mode="Delete"?

janani_10
Explorer
0 Kudos

Hi,

I have created a table and bind json data into it. I have to perform add and delete operations. Add operation works fine. For delete operation, I have used mode="Delete".

For this I have added a function in my controller.

the controller code is

onDelete: function(oEvent) {
			var item = oEvent.getParameter("listItem");
			var path = item.getBindingContext().getPath();
			var idx = parseInt(path.substring(path.lastIndexOf('/') + 1), 10);
			var table = this.getView().byId("idProductsTable");
			var model = table.getModel();
			var data = model.getData();
			data.splice(idx, 1);
			model.setData(data);
		}

I am getting error as ----- data.splice is not a function

By using the below code,

onDelete: function(evt) {  
evt.getSource().removeItem(evt.getParameter("listItem"));
}

I can able to delete the row. But again when i try to add a new entry it's showing error as---- Error: adding element with duplicate id '__text5-__xmlview0--idProductsTable-1'


Please help me with this.

Thanks,

Janani

mantrishekar
Active Participant
0 Kudos

Hi Janani,

Use this below Code snippet.This would work.

var deleteRecord = oEvent.getSource().getBindingContext().getObject();

for(var i=0;i<this._data.Products.length;i++)

{

if(this._data.Products[i]== deleteRecord )

{

this._data.Products[i]

this._data.Products.splice(i,1);

this.jModel.refresh();

break;

}

}

janani_10
Explorer
0 Kudos

Hi Mantri,

May i know, what is _data.Products in the above code?

Thanks,

Janani

mantrishekar
Active Participant
0 Kudos

Hi Janani,

In my case _data is json Array and Products is Entity.

In your case it looks like EmployeeDetails is your entity.

then _data.products can be replaced with your array.entityname(Employee Details.)

janani_10
Explorer
0 Kudos

For the above code, i am getting error as,

mantrishekar
Active Participant
0 Kudos

Could you share the code to mantrishekar951@gmail.com.will check and let you know.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member251534
Participant
0 Kudos

Hi Janani ,

Please check whether Table object is returned correctly .

Also just keep a debugger and check if there is any data "data" array if this is not so then you need to check the binding of table .

former_member182862
Active Contributor
0 Kudos

what path does you bind the rows to?

-D

janani_10
Explorer
0 Kudos

Hi,

I bind the rows with,

 items="{path:'/EmployeeDetails'}" 

and in the controller,

onInit: function() {
			oModel.setData({
				EmployeeDetails: details
			});
			this.getView().setModel(oModel);
		}

In the details, i am having data in json format.

Thanks,

Janani

Former Member
0 Kudos

try data.EmployeeDetails.splice(idx,1) for deleting the specific record

junwu
Active Contributor
0 Kudos

make sure the data is array....