Hi ,

As a part of my project actiities, I need to fetch the data from OData service and show it inside sap.m.Table , however the data was huge and there was a need to implement pagination using $skip and $top values of OData service. There is a chance that user may not view all the records hence , fetching all data in one call and putting it inside model was not advisable hence we went ahead with this approach.

Sample implementation is as follows :

We created a table using XML View which is following the normal coding and at the footer , we placed a button which calls the method getNextOrders.

Inside that method , code is written as follows :

getNextOrders:function(oEvent){

  var sServiceUrl = “ServiceURL”;

  var oDataModel = new sap.ui.model.odata.ODataModel(sServiceUrl);

  var oModel = new sap.ui.model.json.JSONModel();

  var oUrlParams = “$skip=” + gskipValue + “&$top=” + gTopValue;

  oDataModel.read(“/Orders”,null,oUrlParams,true,function(oData, response){

  oModel.setData(oData);

  gOrdersModel.setData(oData);

  });

  this.getView().byId(‘idOrdersTable’).setModel(oModel);

  gskipValue = gskipValue + gTopValue;

  },

gSkipValue and gTopValue are global variable which stores the values to be fetched and skipped. For our implementation , we kept both values as 10. So at a time 10 records will be shown on the screen.

Hope this helps in implementing the pagination for others too. Please share any improving points on the same. Will be helpful for me 🙂 .


Screenshot with demo data from sample service is attached.

Thanks & Regards,

Mahesh.

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Matt Harding

    Hi Mahesh,

    Quick question – Any reason you didn’t use the Growing functionality in sap.m.Table, and set the growingThreshold to 10 to achieve the same result, albeit it would scroll rather than stay in place?

    Cheers,

    Matt

    (0) 
    1. Mahesh Z Post author

      Hi Matt,

      Thanks for your reply.

      Even we tried that thing however what is does is , it fetches all the data in single call. As per our client , the data they have is really huge and there is less chances that user verifies all the data at once. Also , client wanted us to develop some use case where in user can focus on set of order. Growing functionality would append the data to existing results in a table( Correct me if i m wrong) hence if we add more n more orders to table , it would b difficult for user to go through all. Hence we followed this approach.

      But yes, It can be an alternate solution.

      I heard there is some inbuilt pagination in case of sap.ui.table.Table , Currently I am trying that out, Will update this blog once I get any positive output from that.

      Thanks & Regards,

      Mahesh Zeple.

      (0) 
        1. Mahesh Z Post author

          Hello Jun,

          I did not use growing property as I was using JSONModeling at that time. But you can surely use it with Tables here.

          Thanks,

          Mahesh.

          (0) 
        2. Venkatesh Sora

          Growing property doesn’t solve the pagination issue, it’ll still remain as an issue for the end user. Do we have any other solution apart from the one explained & growing property?

          I am looking something of this type:

          Please let me know if anybody have any idea on this.

          Thanks & Best Regards,

          Venkatesh

          (0) 

Leave a Reply