Skip to Content

refresh sap.ui table

Hi Experts ,

    

      I pulled data from a north wind service and displayed data in table .

there is a Create Product button above the table on click of it a pop to create a new product will appear and we can

enter the data and click on submit button , Then a new product is created .But this new product is not visible in the table automatically.

But if i refresh the browser i am able to see the new row (new product) .

Can any body guide me how can I resolve this sothat without refreshing the browser itself the new product should visible in the table automatically .

Please suggest.

I already tried sap.ui.getCore().getModel("Modelname ").refresh(). but no luck .

Thanks

Rizwan

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Oct 06, 2015 at 09:42 AM

    Rizwan,


    There are two options -


    1. As Karthik suggested, after the new entry is created, you need to make a read call and set it to the table model that has been bounded.

    2. One more alternative would be, if you don't want to make a back-end call, then you can just push the new data to your table model, something like this, but this needs to be placed in the create success function.


    var oNewData = {
      ID: "24",
      Name: "twentyfour",
      Description: "twentyfour"
      };
    var oTable = this.getView().byId("productsTabId");
    var oModel = oTable.getModel();
    oModel.push(oNewData);
    
    

    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi All ,

               

      Thanks for all your replies .Any how I got the solution for this as well as the reason why it is not updating in the table also .

      I changed the init method and table xml code as below

      init:

              var oDataModel = new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/V2/(S(u0fm33whthkboho0u01zhgyh))/OData/OData.svc", true);

                

        

              sap.ui.getCore().setModel(oDataModel,"productsModel");

      I did not use the READmethod of ODATA .

      View Code :

      <t:Table id="productsTabId" rows="{productsModel>/Products}"> Here I changed the binding from results to Products

      Now in create function the line of code

      sap.ui.getCore().getModel("productsModel").refresh(true); is updating the model and i am able to see the new product in table .as my table is directly binded to that odata model as shown above ..

      Thanks for all your replies which guided me to find the solution .

      Thanks

      Rizwan

  • Oct 05, 2015 at 06:56 PM

    Hi Rizwan,

    Post your code for updating the data into the model once submit button is clicked.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member rizwan pasha

      Hi,

      I think the problem has something to do with these lines:

      var dModel = new sap.ui.model.json.JSONModel();
      var oDataModel = new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/V2/(S(u0fm33whthkboho0u01zhgyh))/OData/OData.svc", true);
      
      oDataModel.read("/Products", null, null, true,
              function (data) {
                              dModel.setData(data);
              }, function (err) { 
                   alert("inside failure");
              });
              sap.ui.getCore().setModel(dModel,"productsModel");
              this.getView().byId("productsTabId").setModel(dModel);
      

      What I think is happening is that on line 10 you are setting the model to the Locally created JSONModel.

      Then in the onCreate method, you are adding a new entry on the Server side and not in your Local dModel.

      So when you then use the following line

      sap.ui.getCore().getModel("productsModel").refresh(true);
      

      you are refreshing the Local model that doesn't have any new data in it. Even though the oData service does indeed have the new item added.