Giter Club home page Giter Club logo

Comments (7)

ktmsulaim avatar ktmsulaim commented on May 25, 2024 5

pagination: {
enabled: true,
limit: 10,
server: {
url: (prev, page, limit) => ${prev}${prev.includes('?') ? '&' : '?'}limit=${limit}&offset=${page * limit}
},
summary: true,
},

This is how I fixed the bug when not performed search initially

from gridjs.

afshinm avatar afshinm commented on May 25, 2024

Hey @Naravyb

Grid.js calls your server configurations one by one and the prev in your url function is the URL of the previous step. In other words, you have a base URL here:

const grid = new Grid({
  columns: ['Title', 'Director', 'Producer'],
  server: {
    url: 'https://swapi.dev/api/films/',
    then: data => data.results.map(movie => 
      [movie.title, movie.director, movie.producer]
    )
  } 
});

which is https://swapi.dev/api/films/, then you have the search module:

const grid = new Grid({
  search: {
    server: {
      url: (prev, keyword) => `${prev}?q=${keyword}`
    }
  }
  // ...
});

and prev is your base URL in this case since you don't have any other server components. Then, let's say you have a pagination module:

const grid = new Grid({
  pagination: {
    limit: 5,
    server: {
      url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
    }
  },
  // ...
});

Now, prev is actually the URL returned from your search module (the search.server.url function) and you should NOT use ? to append the pagination querystring to your URL and & should be used (because search module already appended the ?q= querystring.

This is the simplified workflow:

  1. https://swapi.dev/api/films
  2. https://swapi.dev/api/films?q=<keyword>
  3. https://swapi.dev/api/films?q=<keyword>&limit=5&offset=10

This is the order of pipeline steps: https://github.com/grid-js/gridjs/blob/master/src/pipeline/processor.ts#L6-L16 and also make sure to read https://gridjs.io/docs/server-side again.

Note: Grid.js sends the final HTTP request once and when all pipeline steps are executed.

from gridjs.

swiftalker avatar swiftalker commented on May 25, 2024

Hmm that's okay, I already implemented it. But I get it again when adding & pagination urls.
Look this

Untitled

I also tried this on the gridjs.io website for testing. but why does he keep having errors?
2

thank u

from gridjs.

swiftalker avatar swiftalker commented on May 25, 2024

while I use code like this, but is there anything more efficient?

      search: {
            server: {
            url: (prev, keyword, page) => `${prev}?q=${keyword}&`
            }
        },
        pagination: {
            limit: 15,
            server: {
                url: (prev, page) => `${prev}?page=${page}`
            }
        },

and this produces the results as expected but what should be like this?

Untitled2

thank you 👍

from gridjs.

afshinm avatar afshinm commented on May 25, 2024

Try:

search: {
            server: {
            url: (prev, keyword, page) => `${prev}?q=${keyword}`
            }
        },
        pagination: {
            limit: 15,
            server: {
                url: (prev, page) => `${prev}&page=${page}`
            }
        },

from gridjs.

pedrocasado avatar pedrocasado commented on May 25, 2024

The hacky ${prev}?q=${keyword}& does work.

The ${keyword} contains {query}?limit=20&offset=1 which will become http://domain.dev?q=query?limit=20&offset=1 (doubled "?")

Maybe its a bug in concatenation?

from gridjs.

aswzen avatar aswzen commented on May 25, 2024

So what the exact solution here?

from gridjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.