Tim
Tim

Reputation: 73

SAPUI5 change row content and write back to table

I have a table which is bound to an XML model.

 var oModel = new sap.ui.model.xml.XMLModel();
 oModel.loadData("http://localhost/xxxxx");

 var oTable = this.getView().byId("TableId");
 oTable.setModel(oModel);
        oTable.bindRows({
            path: "/tageventlist/tagevent",
        })

I am reading the rows in my controller simply like this:

var oItems = this.byId("TableId").getRows();

Now I loop through the items and I need to change the contents of 2 fields:

for (var i = 0; i < oItems.length; i++) {
     oItems[i].mAggregations.cells[1].mProperties.unit = 'NewUnit';
     oItems[i].mAggregations.cells[0].mProperties.title = 'NewTitle;
 }

I can see the changed values in the debugger but how can I write the changed values back to the table? Any ideas?

Thanks, Tim

Upvotes: 0

Views: 4539

Answers (1)

Stephen S
Stephen S

Reputation: 3994

To change the values in the model, you can loop over the rows to get the binding context. The binding context will give you the binding path which can be used to set properties in the model.

var oItems = this.byId("TableId").getRows();
var oModel = this.oTable.getModel();

oItems.forEach(function(oItem){
    var oContext = oItem.getBindingContext();
    oModel.setProperty(oContext.getPath()+"/unit ","NewUnit");
    oModel.setProperty(oContext.getPath()+"/title  ","NewTitle");
});

Upvotes: 1

Related Questions