Skip to Content
0

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

Nov 10, 2017 at 10:28 AM

110

avatar image

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

10 |10000 characters needed characters left characters exceeded

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;

}

}

0

Hi Mantri,

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

Thanks,

Janani

0

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.)

0

For the above code, i am getting error as,

error.png (26.5 kB)
0

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

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

tisha dharod Nov 13, 2017 at 09:08 AM
0

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 .

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Nov 10, 2017 at 12:36 PM
0

make sure the data is array....

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member
Nov 11, 2017 at 02:40 AM
0

what path does you bind the rows to?

-D

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0
Former Member

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

0