Skip to Content
0

How remove item from Model?

Dec 26, 2017 at 06:26 PM

100

avatar image

Hey guys.

I want remove item from model.

I finded this code;

for(var i=0; i<aSelectedItems.length; i++){
   var oItemContextPath = aSelectedItems[i].getBindingContext().getPath()
   var aPathParts = oItemContextPath.split("/");
   var iIndex = aPathParts[aPathParts.length - 1]; //Index to delete into our array of objects
   var oJSONData = this.getView().getModel().getData();
   oJSONData.correlationData.splice(iIndex, 1); //Use splice to remove your object in the array
   this.getView().getModel().setData(oJSONData); //And set the new data to the model
 }

And i using this;

var oTable = this.getView().byId("mesaiTable");
var sSelectedItems = oTable.getSelectedItems();
var oModel = this.getView().getModel();
var oTempData = oModel.getData(); **//THIS CODE RETURNING 'UNDEFINED'******

for (var i = 0; i < sSelectedItems.length; i++) {
var oItemContextPath = sSelectedItems[i].getBindingContext().getPath();
var aPathParts = oItemContextPath.split("/");
var iIndex = aPathParts[aPathParts.length - 1];
oTempData.XXXX.splice(iIndex, 0); ---> And I dont know XXXX. Table items Path? or not ?

Please help. Just I want delete item from model.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Irfan Gokak Dec 27, 2017 at 08:03 AM
0

Hi,

If you're trying to remove rows from the table. then it as below.

var oTempData = oTable.getModel().getData();
// Now get the selected index and split it.
oTempData.results.splice(iIndex, 0);
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Show me your code how your fetching data from backend system. Please show me that first. And how you're setting the data.

0
Ivan Mirisola
Dec 27, 2017 at 02:44 PM
0

Hi Burak,

Declare a delete handler on your table just like this document explains.

Once you have declared the event handler, you need to retrieve the selected row and remove it from the model just like explained on this sample for a List item. The only difference is that you need to get the selected "rows". Now for this it depends on which sapui5 element you are using as Table.

sap.ui.table.Table:

var bindInfo = oTable..getSelectedItems().getBindingInfo("rows")

sap.m.Table:

var bindInfo = oTable..getSelectedItems().getBindingInfo("items")

Now you can retrieve the path to your model from the bindInfo object like this:

this.oJsonModel.remove(bindInfo.path);

Regards,
Ivan

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

Thank you for answer.

I using sap.m.table

i tryed this 2 code.But I got an error. Error ;

"oTable.getSelectedItems(...).getBindingInfo is not a function"

var oTable = this.getView().byId("mesaiTable");
//var bindInfo = oTable.getSelectedItems().getBindingInfo("items")
//var bindInfo = oTable.getSelectedItems().getBindingInfo("rows")
0

Hi Burak,

Sorry I confused the table stuff with export features.

Please check this project I shared on github that contains the correct working code to remove items from the model and update/refresh it on the UI.

Regards,
Ivan

0
Joseph BERTHE Dec 26, 2017 at 09:55 PM
0

Hello,

Is your model come from an OData, if so use your back end to do it.

Otherwise did you look at this blog : Link

Regards,

Joseph

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

Hello,I was doing this;

The data comes from oData.I'm sending the data to backend.And i removing datas. But the display on the screen is still standing.And i using this code;

this.getView().getModel().refresh(true);

The data is reloaded from the entityset.

But after the data was erased, I realized I was calling unnecessary service.So I wanted to delete it from the model.

thanks


0

Is your problem solved ?

Regards,

Joseph

0

No. continues.

Regards.

0
avatar image
Former Member
Dec 29, 2017 at 01:41 AM
0

var oModel = this.getView().getModel();

should be

var oModel = oTable.getModel();

and here is a simple example, http://jsbin.com/pulenom/edit?html,js,output

Share
10 |10000 characters needed characters left characters exceeded