Skip to content
This repository has been archived by the owner on Jul 4, 2021. It is now read-only.

Currentpage-like support for skipped (OData) #358

Open
nrdev88 opened this issue Mar 13, 2017 · 3 comments
Open

Currentpage-like support for skipped (OData) #358

nrdev88 opened this issue Mar 13, 2017 · 3 comments

Comments

@nrdev88
Copy link

nrdev88 commented Mar 13, 2017

We're using a project with OData currently. But it would be nice to have this project support the "$skip" param instead of the current "currentpage" param.

OData uses "$top" (pagelimit) and "$skip" (currentpage * pagelimit) to create data offsets. It's a simple implementation next to the current and would be nice to have!

@mookfist
Copy link

+1

dealing with an API that uses offset/limit rather than page/limit

@alex-dow
Copy link

I too ran into this problem. I had to implement my own solution:

    state: {
        firstPage: 0,
        currentPage: 0,
        pageSize: 5,
        offset: 0
    },  
    queryParams: {
        pageSize: 'limit',  // LIMIT in SQL speak
        start: 'after'          // OFFSET in SQL speak
    },  

    getOffset: function() {
        console.log('getOffset:', this.state);
        return this.state.currentPage * this.state.pageSize;
    },  

    fetch: function(options) {

        if (!options) {
               options = {}; 
        }   
        if (options['data']) {
            options['data']['after'] = this.getOffset();
        } else {
            options['data'] = { 
                'after': this.getOffset()
            };  
        }   

        return PaginatedCollection.prototype.fetch.call(this, options);
    }

All the terminology here is annoying if you're used to offset/limit terminologies. The API I'm using uses the terms "after/limit" while backbone.paginator uses "start/pageSize" but SQL uses "offset/limit".

So far this seems to work as expected but do I get unnecessary query params in my API request. I can live with that...

@jackbentley
Copy link

If I'm not wrong, the example from the readme solves this nice and succinctly? (I think that's where I first found it?)

  queryParams: {
    pageSize: "limit",
    // Setting a parameter mapping value to null removes it from the query string
    currentPage: null,
    // Any extra query string parameters are sent as is, values can be functions,
    // which will be bound to the pageable collection instance temporarily
    // when called.
    offset: function () { return this.state.currentPage * this.state.pageSize; }
  },

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants