4 Replies Latest reply on Apr 15, 2014 10:04 AM by stefanbe RSS
    stefanbe Explorer

    QueryImplementingThings & paging

    Hi,


    I was wondering if it's possible to implement paging with QueryImplementingThings (e.g. return 10 things at a time)? 


    I see that a 'TopN' filter exists, but I don't see an 'Offset' filter or something like that which could be used to implement paging (e.g. 'return 10 things starting from position 0, then from position 10, 20, ...). Is there another way to do paging?


    Thanks!


    Stefan



      • QueryImplementingThings & paging
        adam Creator

        Hi Stefan,

         

        What is the use case for pagination?

          • QueryImplementingThings & paging
            stefanbe Explorer

            Hi,

             

            Well, depending on the situation, we have pagination or lazy loading / scrolling. On the backend, this comes down to the same thing. This is mainly for performance reasons, so that not all data is loaded from the DB and sent with every request. 


            For the data that is stored in a MS SQL database, this can be done easily. But for ThingWorx Things & QueryImplementingThings I haven't found a solution, besides duplicating everything in a separate database.



          • QueryImplementingThings & paging
            adam Creator

            Stefan,

             

            Have you noticed performance issues when using QueryImplementingThings() on your data set? Having spoken with several colleagues, the consensus is that pagination is only warranted in a few cases. ThingWorx does not provide any built-in functionality for pagination, so unless you are seeing performance issues, it may not be worthwhile to implement the possible pagination solution I'll detail below.


            Provided your data is sorted and the column on which you are sorting is unique, you can use a combination of TopN() and a query to implement pagination. Since you will be working with unique Things, you can do a greater than or less than comparison on the last row of data returned and specify the page size using TopN(). For example, if you have five Things ('A', 'B', 'C', 'D', 'E') and want to display two at a time, you would do a greater than comparison on 'B' and return the top two entries from that result ('C', 'D').


            Thanks,

            Adam