Search code examples
sapui5

UI5: refresh Table containing relative timestamp without changes in the Model


The Problem

I am currently working on a View containing a Table. One of the columns is a relative time stamp of the last update of the elements in the table (Last Update: 6 seconds ago), using

<Text text="{
  path: 'lastUpdate',
  type: 'sap.ui.model.type.DateTime',
  formatOptions: {
    source: {pattern: 'yyyy-MM-ddTHH:mm:ss.SSSZZZZ'}, 
    relative: true,
    relativeScale: 'auto'
  }
}"/>

Until now I have transmitted the current model from the backend with every get request, so the view always updated itself with the model on every update. However, to save bandwidth I have decided to place in a If-Modified-Since condition into the call, so that the backend will only send me the model if it actually has been updated since the last call, otherwise it returns a 304.

The issue I'm having now, however, is that since the model doesn't get replaced anymore, the view is equally not updated and the most recent event will be stuck on e.g. "Last Update: 15 seconds ago" for potentially minutes; until a new update comes in.

Question

I'm looking for a function that tells the view (or even just the table or the particular column) to refresh its content according to the new current time, even if the underlying data has not changed.

So far, I found and tried

that.byId("myTable").getBinding("items").refresh();

but that didn't do anything, I assume because it still recognized that the data hadn't changed.

Edit: Going by the accepted answer, calling that.getView().getModel().refresh(true); did yield the intended results.


Solution

  • Have you tried to use .refresh(true)

    The DemoKit show for the sap.ui.model.odata.v2.ODataListBinding:

    refresh(bForceUpdate?, sGroupId?) : void
    

    with bForceUpdate meaning "Update the bound control even if no data has been changed"