cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with sap.m.table refresh on UI screen

Former Member
0 Kudos
1,196

Hi All,

I have created a custom UI5 app. In View1, I have used sap.m.table for user input. The table is initially blank, where user can add/ delete rows. After saving the data of the table, I am navigating to View2. But when I come back to View1, the data entered by the user is still there, and not getting refreshed. I have tried the following syntax, but it doesn’t help. I'm saving, adding, deleting, and changing data on the back end, but the UI screen doesn't seem to be cleared/ refreshed. Please advise.

onInit: function () {
                  this.oScopeTable = this.getView().byId("idtable_newDeal");
                  var TableModel = new sap.ui.model.json.JSONModel([]);
                  this.getView().setModel(TableModel, "tableModel");
                  this.onAddRow();
            }

                  onAddRow: function (oEvent) {
                  var tableModel = this.getView().getModel("tableModel");
                  tableModel.getData().push({});
                  tableModel.refresh();
            },

            onRefresh: function () {
                  // this.getView().getModel("tableModel").setData({
                  // tableModel: {}
                  // });
                  // this.getView().getModel("tableModel").refresh(true);
                  // this.oScopeTable.getModel().refresh(true) ;
                  // this.oScopeTable.getBinding("rows").refresh();
                  // this.oScopeTable.getBinding("items").refresh();
            }

Accepted Solutions (0)

Answers (3)

Answers (3)

junwu
Active Contributor
0 Kudos
 var tableModel = this.getView().getModel("tableModel");
tableModel.setData([])
Wojciech_P
Product and Topic Expert
Product and Topic Expert
0 Kudos

HI,

maybe you can try following code for refresh data in table:

tableModel.updateBindings(true);

Best Regards

WouterLemaire
Active Contributor
0 Kudos

where do you save the data to the backend? I only see logic storing it in a json model…


not makes sense that it is not cleared when you come back to view 1. The onInit function is only called the very first time. Afterwards you need to use routing and an route matched eventhandler, see example:

https://ui5.sap.com/#/topic/516e477e7e0b4e188b19a406e7528c1e

sap.ui.require([
    "sap/ui/core/mvc/Controller",
    "sap/ui/core/UIComponent", ...
], function(UIComponent, ...) {
    "use strict";
    return Controller.extend("MyApp.View1", {
        onInit: function() {
            var oRouter = this.getOwnerComponent().getRouter();
            oRouter.getRoute("view1").attachMatched(function(oEvent) {
                this._selectItemWithId(oEvent.getParameter("arguments").id);
            }, this);
        },
    
        _selectItemWithId : function(id) {
            //implementation
        }
    });
});
Former Member
0 Kudos

Hi wouterelia

I have not added the code of onSave method in the above snippet. The data is being stored in a backend table. After onSave method, I am calling onRefresh method to clear screen data. But unfortunately, it is not getting refreshed.