Skip to Content
0

List doesn't have updated data after getBinding().refresh

Aug 08, 2017 at 01:45 PM

59

avatar image
Former Member

Hi,

I use odata model (v2) for my Master-detail template. In the detail view, when some lines are selected -> some action done -> and on Save, I am calling submitchanges to post the data to the backend. I want the detail list to be refreshed with the updated data, but it is not.

this.getView().byId("detail").getBinding("detailitems").refresh(true);

After this line, when I try to access the value of the list in array, I still get the old values.

But in the event onListUpdateFinished, I get the latest values of the list,

Is this the design ? I see in may threads that by calling model.refresh(), one would be able to get the latest updated data,

The reason why I want to have it within the submitchanges call is, based on the values for all the records in the detail, I need to update a value for the master. This happens instantly if I just set a dummy value, but as I still get the old value, I have the same logic in listupdatefinished, where I face the issue that the master.XYZ value isn't displayed instantly. Only when I choose another item in the Master and come back, I am seeing the latest value,

Any help here is appreciated,

thanks,

Sathish R

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

3 Answers

Sharath M G Aug 08, 2017 at 02:25 PM
0

try to clear the entries in the list and then a refresh. By clearing, you should not have any old values and then loading new values should result in the fresh set of values in the list.

Regards,

Sharath

Share
10 |10000 characters needed characters left characters exceeded
Srikanth KV Aug 08, 2017 at 03:41 PM
0

you should refresh the model data in the action(eg: create/update/delete) ...then perform submit changes. Check the below code assuming that you are updating a list item.

"update" method has a property called "refreshAfterChange"...this needs to be set

oModel.update(
       "<path to ODATA entity set>",
       "<Data to be updated>",
       {
           success: function(){},
           error: function() {},
           refreshAfterChange: true      //this needs to be set to refresh model data after submit changes automatically
       }
);

//Submit changes to DB
oModel.submitChanges();
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Aug 09, 2017 at 12:51 PM
0

Hi Sathish,

Where did you call this.getView().byId("detail").getBinding("detailitems").refresh(true)? Is it after the submitchanges()?
if yes the most reasonable reason that you still get the old value is because the update is an async process, and after the submitchanges() executed the line after that (in this case is the refresh binding item line) will be executed without waiting for the update to be finished.

There are 2 ways to solve this (Hope it helps) :

oModel.update(oData, sPath, {
    success : function() { 
         this.getView().byId("detail").getBinding("detailitems").refresh(true) 
    }.bind(this)
});
//OR

oModel.update(oData, sPath, {
           success: function(){},
           error: function() {},
           //Defines whether to update all bindings after submitting this change operation
           refreshAfterChange: true 
       }
);
Share
10 |10000 characters needed characters left characters exceeded