Newly added line item is getting removed after making changes in data which is already bound to sap.m.Table

Viewed 58

We have to perform edit functionality where we have to take two scenarios into consideration:

  1. Make changes in existing entries.
  2. Add new entries and update the old entries.

In the 2nd scenario, when we are trying to add a new entry, it is getting added to sap.m.Table but if we make any change in the old entry then the newly added line item is disappearing.

let oContextLineItemEntry = oLineItmTab.getModel().createEntry("/EntityName", {
  properties: NewLineItem,
});
let oTmp = oLineItmTab.getBindingInfo("items").template,
oItem = oTmp.clone();
oItem.setBindingContext(oContextLineItemEntry);
oLineItmTab.addItem(oItem);

Here NewLineItem is an object which I want to add and it is blank. It is initiated like below:

NewLineItem = oLineItmTab.getItems()[0].getBindingContext().getObject();

After this, I have removed all the values of the objects attribute.

I tried with OData V2 OneWay binding, but it didn't work.

I saw framework behavior is triggering this interaction

  1. onChange started
  2. onChange completed

I went through these questions on SAP Community:

1 Answers

After you bind an aggregation it will be managed by the data binding. Therefore you should not try to modify the aggregations. Instead, do the changes in the model and then the aggregation should be updated according to data in the model. e.g.

let newRow = {key: "_your_unique_id_", value: ""};
let model = table.getModel();
let tableData = model.getProperty("/tableEntityName");
tableData.unshift(newRow);
model.setProperty("/tableEntityName", tableData);

Besides that consider to set the growing property of the table to true.

Related