cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Binding sap.m.Table Odata data dynamically after user changes table values in UI

Former Member
0 Likes
4,895

Hi,

I have a problem and need your help in solving the same. I am a newbie in SAPUI5

I am creating a Master/Detail SAP UI5 application which displays list of Articles on left Master page and Variants on Detail page. The implementation is similar to EPM_OIA_BPOENINV example, SAP provided in 740, creating object of Shell to hold both Master and Detail XML views.

I created two entity sets, ARTICLEINFOSET and VARIANTINFOSET and maintained navigation between them. It's working perfectly fine, with 2 Odata services including BATCH operations to save the data.

The Model is set to SAP.UI.GETCORE() by passing url to Model object:

    var url = model.Config.getServiceUrl();

    m = new sap.ui.model.odata.ODataModel(url, true);

    sap.ui.getCore().setModel(m);


So all Odata requests are now binded to this level.


In the Master view, I defined sap.m.List with "items" attribute pointing to "{path : '/ARTICLEINFOSET'}". This calls OData service and fetches the Articles and binds to the List.


In Detail view, I defined sap.m.Table with with "items" attribute pointing to "{path : '/VARIANTINFOSET'}". This calls OData service and fetches the Variants, for the corresponding Article selected in the left navigation and binds to the List.


Now, the problem, I have a custom button declared in Detail Footer section which on clicking, gives a Mass Update pop-up, which on entering a value, the corresponding data should be updated back to Sales Order Item Quantity field in all rows. And here I am stuck. I am not getting clue on how to update data which is bound to the table.


As mentioned, all my data getting displayed in the view is present in Model, which is bound at application level.I don't have explicit Table declarations in javascript.


Model's Default Binding Mode is "OneWay". "TwoWay" is not working.It's only updating first row and then binding for next rows, it's showing getAggregation is NULL. So I need to do this change only by "OneWay".


Request you all to guide me in solving this issue.


Accepted Solutions (1)

Accepted Solutions (1)

Former Member

With the UI5 odata V2 model, you can do it quite simple. You can try something as below on mass update,


//store all the context/contextPath of the table in an array

var aContexts = oTable.getItems().map(function(oItem){                            

          return oItem.getBindingContext().getPath(); // binding path

});

  

  //iterate over the context array and change values in the model

aContexts.forEach(function(sPath){

           model.setProperty(sPath+'/<property-to-be-updated>',"<value>");

});

  

//submit all the changes to the backend.

model.submitChanges();

You can find a simple example - JS Bin - Collaborative JavaScript Debugging

Former Member
0 Likes

Hi,

Thanks a ton Maksim and Sakthivel.. It's working flawlessly now with V2 Odata Model

But I have one more problem. In SAVE method, when i am calling submitChanges(), it's not displaying any alerts:

this.getView().getModel().submitChanges(function() { 

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

  alert("Update successful"); 

        },

  function() { 

            alert("Update failed"); 

        }

); 

Any reason why no pop-up is getting displayed ? Or How can I display the pop-up on successful SAVE ?

former_member182372
Active Contributor
0 Likes

this.getView().getModel().submitChanges(

{

  success :  function() {

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

  alert("Update successful");

  },

  error :  function() {

  alert("Update failed");

  }

}

);

Former Member
0 Likes

Thanks again

As of now I have screen as displayed below. Search button is on top of Master Page. Master/Detail pages are part of Split-App, default view.

Now I need to create a new simple Search view, which will be first displayed and then on 'Search', it should navigate to Split-App view and back and forth.

Shall I create new thread for this ?

Thanks,

Harish

former_member182372
Active Contributor
0 Likes

i would think it is a different topic, so yes, new thread 😉

TimMuchena
Participant
0 Likes

Hi Sakthivel

Thank you very much. This helped me as well

Much appreciated

Answers (2)

Answers (2)

former_member182372
Active Contributor
0 Likes

is using v2 ODataModel an option?

If not, the only way IMHO is to copy values to JsonModel and copy back when submitting

Former Member
0 Likes

We are using ODataModel to read the information from SAP backend and bind the same in UI.

I tried the other way too, but unable to display any data..

former_member182372
Active Contributor
0 Likes

what`s sapui5 version? above 1.28?

Former Member
0 Likes

Yes, we are on 1.30.6.

former_member182372
Active Contributor
0 Likes

switch to

sap.ui.model.odata.v2.ODataModel

set two way binding, and when you wanna submit changes to server just call submitChanges

SAPUI5 SDK - Demo Kit

Former Member
0 Likes

Did the same. Changed to v2 model. and set TwoWay binding. But I want to know how to update the changes from the pop up value to Odata model's table items.

With V2 Odata model as well, I am able to SAVE the changes by using submitChanges(). But still not able to change the UI table column values. Here is the code for Mass Update functionality. With TwoWay, it's updating first row and then displaying getAggregation is NULL:

It's updating Model.OData bindings but not the table aggregations

Any info on how to update the aggregations.

When I try to update using the below code, it's updating first record and then saying, getAggregation is NULL for second iteration:

aItems[i].getAggregation("cells")[3].setProperty("value", newtgtstk);

Former Member
0 Likes

To do the UI changes to the table, I used oTable.getModel().updateBindings(); and now the UI is updated with new values, as I am doing changes to the Odata data in the Model.

But with this, now Model.submitChanges stopped working, as I think, Bindings had been updated with above statement and Model is not able to recognize any changes done.

So I switched back to V1 Odata Model and started using "createBatchOperation" and "submitBatch" to manually tell Model to update the changes even after bindings were updated.

Former Member
0 Likes

Any info to proceed further on this ??