cancel
Showing results for 
Search instead for 
Did you mean: 

Refresh SAPUI5 table data

Former Member

Hello Experts,

What I am looking out for is to refresh or reload data into SAPUI5 table. The model associated with the table is a JSON model. Is there an option to refresh the table or reload data into the JSON model and then the table?

Basically I want the whole table to be refreshed on click of an image in the table column. Any help would be really helpful. Thanks in advance.

Thanks & Regards,

Archana

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

i am using this

sap.ui.getCore().byId("mytableid").getModel().refresh(true);


in my JSON MODEL    but it doesn't working,


please help me, how to refresh the UI5 table data with synatax

yoppie_ariesthio
Participant
0 Kudos

I'm using oData, console.log(sap.ui.getCore().byId("idmytableview')) return undefined. Please help.. What should i do?

former_member192494
Participant
0 Kudos

Hi Yoppie,

In case you are trying to access the view "idmytableview" from different view, Just check if the view "idmytableview' is loaded. If this view is not loaded, this corresponding view or its contents will not be available and returns Undefined.


If not, in which context are you getting this error.

Regards,

Ravikiran

yoppie_ariesthio
Participant
0 Kudos

Dear Ravi,

I got view table loaded at onInit function on my controller. The code i used to insert is on the same controller. just different function...

Need to bindRows again on another function..

Thank you

former_member192494
Participant

Hi Yoppie,


If i am correct, you should be using XML view.

Can you check below this line of code,

this.getView().byId("idmytableview");


Regards,

Ravikiran

former_member192494
Participant
0 Kudos

Hi All,

I have a case of resetting the model on click of a button, i tried this method.

sap.ui.getCore().byId("THE_ID_OF_YOUR_VIEW").getModel().refresh(true);

I am able to call the view and model as well, but not able to refresh the model, which says "undefined".

Am I missing something here, please correct me if wrong.

Thanks,

Ravikiran

Former Member
0 Kudos

Hi Ravi,

          Actually what is your 'THE_ID_OF_YOUR_VIEW'

former_member192494
Participant
0 Kudos

Hi Jagadish,

this is my "EventCreateView",

Thanks,

Ravikiran

Former Member
0 Kudos

Thanks for your reply guys.As Robin said, I am reexecuting the AJAX call to DB. I thought there would be some API using which I can trigger the refresh and AJAX call.

But this reexecution is working for me. SO, thats fine.

0 Kudos

Hi Archana,

I am new to UI5, can you share your code syntax.

Thanks,

Bheki

Former Member
0 Kudos

Hi!

Try this:

sap.ui.getCore().byId("THE_ID_OF_YOUR_VIEW").getModel().refresh(true);

Best, Silvia

former_member182372
Active Contributor
0 Kudos

model.refresh(true);

Former Member
0 Kudos

Didnt work for me. says the method is undefined.

Is there a general way in which we c reload data into all controls in sap.ui.commons

Qualiture
Active Contributor
0 Kudos

Honestly, I have never felt the need to use any of the UI5 refresh or invalidate methods yet

Normally, if your table is bound to your model, any changes you do to the model (whether via user interaction or updating via REST etc) would instantly be reflected in your table (or any other controls bound to your model)

Former Member
0 Kudos

Thanks Robin. Completely agree to your point. Let me explain what I want to achieve.

I have a table bound to a JSON model. Now, I need to reload the same JSON data again on click of an Image in the table column(Obv, the data changes in the backend. Hence the data in JSON again needs to be refreshed.)

I am looking out for an option to achieve this. If I do table.invalidate and table.rerender, it isnt changing the JSON data which is what I am looking for. I just want to avoid calling the DB again and again.

I hope this can be achieved in some way.

Thanks & Regards,

Archana

Qualiture
Active Contributor
0 Kudos

If the data is changed on the backend you just re-execute the ajax call to retrieve the JSON table data from your backend, and your table automagically displays the updated data.

And if you make changes to the table data from the frontend, your JSON should also be updated and your table displays the same updated data.

On a sidenote, if the data on the backend differs from what is displayed in the frontend, you should always update your frontend with the data from your backend to avoid synchonization / data mismatch issues

0 Kudos

It sounds like you're updating the JSON directly -- when you create the model, (e.g. new sap.ui.model.json.JSONModel(this.modelData) ) the source JSON is cloned into the model, and you need to use the set*() methods of sap.ui.model.json.JSONModel to update the model. I'd actually advise you *not* to keep a JSON object outside the model, since this copy would not get any updated values from the view bindings.