Search code examples
odatasapui5

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


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:


Solution

  • We had raised an OSS note for this issue to which SAP replied, this is not and issue with UI control but the way to use it. Basically we are not supposed to add new entries when OData binding is being used.