Giter VIP home page Giter VIP logo

Comments (9)

lixxu avatar lixxu commented on May 27, 2024 2
pagination = Pagination(p=5,
                        per_page=10,
                        total=1000,
                        page_parameter='p',
                        css_framework='bootstrap4')

when you set page_parameter to p, you also need to set p=5 instead of page=5.

from flask-paginate.

lixxu avatar lixxu commented on May 27, 2024

What are the parameters to the Pagination?

from flask-paginate.

aldacron avatar aldacron commented on May 27, 2024

Sorry, it wasn't clear to me that I had to change "page" to "p" since I changed it in page_parameter. Would appreciate if this got documented!

from flask-paginate.

fzalkow avatar fzalkow commented on May 27, 2024

This was also very confusing for me and should definetly be better described in the docs. For others having the problem: Instead of the page argument name, this argument name has to be the same as the value you pass to page_parameter.

Since I have multiple Paginators on the same page, I generate my pagination ids automatically. So now I end up with something like this:

pagination_id = generate_pagination_id()  # ... generated somehow 
page, per_page, offset = get_page_args_with_param(pagination_id)

pagination = Pagination(total=total_items,
                        page_parameter=pagination_id,
                        **{pagination_id: page})

Also I needed to customize get_page_args a bit:

# slightly modified version of flask_paginate.get_page_args to support the `param` argument
def get_page_args_with_param(param='page'):
    args = request.args.copy()
    args.update(request.view_args.copy())
    page_parameter = args.get('page_parameter', param)
    page = int(args.get(page_parameter, 1))
    per_page = args.get('per_page')
    if not per_page:
        per_page = current_app.config.get('PER_PAGE', 10)
    else:
        per_page = int(per_page)

    offset = (page - 1) * per_page
    return page, per_page, offset

from flask-paginate.

lixxu avatar lixxu commented on May 27, 2024

I update it to version 0.5.0 which can customize page_parameter and per_page_parameter, please try.

from flask-paginate.

lixxu avatar lixxu commented on May 27, 2024

close as long time pending.

from flask-paginate.

jwitos avatar jwitos commented on May 27, 2024

Hi @lixxu, can we reopen this issue? I think the issue might still exist.

To reproduce, you can hardcode the following Pagination object:

pagination = Pagination(page=5,
                        per_page=10,
                        total=1000,
                        page_parameter='p',
                        css_framework='bootstrap4')

Going to route with &p=5 ignores the active page, says that it is displaying 1 - 10 records in total 1000 and marks page 1 as active.

When changing back to:

pagination = Pagination(page=5,
                        per_page=10,
                        total=1000,
                        page_parameter='page',
                        css_framework='bootstrap4')

it correctly displays pagination with displaying 41 - 50 records in total 1000 and page 5 as active.

from flask-paginate.

jwitos avatar jwitos commented on May 27, 2024

@lixxu I found the problem causing this:

Pagination object is initialized and self.page takes a kwarg equal to self.page_parameter:

self.page = kwargs.get(self.page_parameter, 1)

So, if page_parameter="p", Pagination will ignore page=5 kwarg and look for p=5.

Changing that line to:

self.page = kwargs.get("page", 1)

solves the problem. Happy to do a PR if you'd like.

from flask-paginate.

jwitos avatar jwitos commented on May 27, 2024

@lixxu, yes, thank you. Personally I found it pretty confusing, but if you would like to keep this behavior, I would be happy to make a PR to update docs making this more clear.

from flask-paginate.

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.