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

Currentpage-like support for skipped (OData) #358

Open

Description

@nrdev88

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!

Activity

  1. mookfist commented on Sep 19, 2017

    @mookfist

    +1

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

  2. alex-dow commented on Sep 20, 2017

    @alex-dow

    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...

  3. jackbentley commented on Jan 31, 2018

    @jackbentley

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions