Git Product home page Git Product logo

Comments (13)

blatyo avatar blatyo commented on May 14, 2024

It would be nice to set the name of the parameter when there is more than one collection being paginated; otherwise, it would conflict. For example, you could have pagination for customers and employees on two tabs in the same page. When the page is changed for one, since :page is used for both, it is indistinguishable which collections page should be changed.

from kaminari.

l15n avatar l15n commented on May 14, 2024

Here's a naive patch that allows you to localize links by adding the translation string views.pagination.page to your locale.

diff --git i/lib/kaminari/helpers/tags.rb w/lib/kaminari/helpers/tags.rb
index 6fdb13a..ce4753c 100644
--- i/lib/kaminari/helpers/tags.rb
+++ w/lib/kaminari/helpers/tags.rb
@@ -47,7 +47,8 @@ module Kaminari
       end

       def page_url_for(page)
-        @template.url_for @template.params.merge(:page => (page <= 1 ? nil : pa
+        page_param = I18n.t('views.pagination.page').to_sym
+        @template.url_for @template.params.merge(page_param => (page <= 1 ? nil
       end
     end

EDIT: You'd also have to do the same for the :page at around lines 97 and 170 in the same file

The problem with this patch is that you'll have to write something ugly in your controller.

@users = User.order(:name).page params[I18n.t('views.pagination.page').to_sym]

Writing that over and over will probably make you want something like this:

module Kaminari
  def self.page_param
    I18n.t('views.pagination.page').to_sym
  end
end

This will work, but I'm not very happy with the API.

from kaminari.

l15n avatar l15n commented on May 14, 2024

Buggy, ugly, possibly incomplete implementation of the above "fix"

https://github.com/l15n/kaminari/tree/i18n-param

Probably doesn't work properly. But it might...

I have a feeling that the using the i18n API here is a bad idea. Should parameter names really change for each language? I'm uncomfortable with the idea of parameter names changing based on the users locale.

Perhaps a good compromise would be to allow the name for the page parameter to be set on a per-application basis rather than a per-locale basis.

from kaminari.

amatsuda avatar amatsuda commented on May 14, 2024

l15n
Thanks for the patch!

But seeing blatyo's comment and some comments on the Railscasts' episode http://railscasts.com/episodes/254-pagination-with-kaminari
I guess it's better to simply add a new option for the parameter name to the paginate helper.
I think I finished adding the option, so it will be enabled since 0.10.2.

from kaminari.

blatyo avatar blatyo commented on May 14, 2024

I would prefer an API that would allow me to set the parameter name on the call to paginate. For example:

<%= paginate @users, :page_param => I18n.t('views.pagination.page').to_sym %>

Also, I think it would be a reasonable convention to name the parameter after the plural name of the type of records being paginated. For example, paginate @users would by default set :param_name => :users_page. This would allow for multiple paginations to be on the same page without having to set :param_name every time.

Finally, the default place to look for a localization could be views.pagination.<param_name> where param_name would be something like users_page. Then the logic for deciding what to use as the parameter would be something like this inside page_url_for:

page_param = I18n.t("views.pagination.#{page_param}").try(:to_sym) || page_param

Unfortunately this doesn't fix the problems you noted with the patch you proposed. However, I would discourage a single page parameter, because it isn't flexible for multiple paginations on the same page.

EDIT: Wrote this before seeing the two comments above this.

from kaminari.

amatsuda avatar amatsuda commented on May 14, 2024

Oops. Lots of comments! So, this is my commit.
amatsuda@5826382
Are you OK with this?

from kaminari.

blatyo avatar blatyo commented on May 14, 2024

@amatsuda, I can certainly meet my use case with this solution.

Do you have any comment about changing the default param_name? For example:

def paginate(scope, options = {}, &block)
  Kaminari::Helpers::PaginationRenderer.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => inflect_param_name(scope), :remote => false)
end

private

def inflect_param_name(scope)
  scope_type = scope.first.try(:class).try(:name).try(:downcase)
  scope_type ? :"#{scope_type}_page" : :page
end

from kaminari.

ivanyv avatar ivanyv commented on May 14, 2024

@amatsuda thanks for the quick work! I tested the branch and at first it appears to work, but after going to a page, the links for the pagination get an additional parameter. Say the current page is 3, param_name is 'pagina', the link to page 4 will be: ?page=3&pagina=4

from kaminari.

amatsuda avatar amatsuda commented on May 14, 2024

@IvanVr Thank you for testing! But that doesn't happen for me...
Maybe I'm missing something, but anyway let me push this to master and ship another gem because this change won't cause any regression to the existing apps.

from kaminari.

amatsuda avatar amatsuda commented on May 14, 2024

@blatyo Well, I tested that but the URL looks a bit redundant, so I don't like this to be the default.
http://example.com/books?book_page=3

from kaminari.

amatsuda avatar amatsuda commented on May 14, 2024

I'm sorry this ticket are going to be automatically closed as I push my commit to master.
Feel free to reopen or create another ticket if you want to keep the discussion open.
Thanks!

from kaminari.

amatsuda avatar amatsuda commented on May 14, 2024

closed by f9f529f add :param_name option to the helper

example: <%= paginate @users, :param_name => :pagina %>

from kaminari.

ramisn avatar ramisn commented on May 14, 2024
  1. I have two tabs in index-page , when i click on first tab it show 12 item and load more using infinite-scroll pagination.
  2. I have used like this in view,
<%= paginate @articles %>

and

<%= paginate @most_popular_articles, :remote => true, :param_name => 'pagina' %>

But, /?page=3&pagina=1. like, page is updating while scrolling; pagina is not updated.
Parameters: {"page"=>"4", "pagina"=>"1"}. please fix the issue.

from kaminari.

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.