Go to the average by pagination Kaminari

Say I have 30 pages paginated with Kaminari:

#800 books, 25 per page =paginate @books, :outer_window => 3, :window => 3 

It looks like this:

1 2 3 4 ... 30 31 32

It is not possible to go to page 16 without pressing 5 times.

  • 1 * 2 3 [4] ... 30 31 32
  • 1 2 3 4 * 5 6 [7] ... 30 31 32
  • 1 2 3 4 5 6 7 * 8 9 [10] ... 30 31 32
  • 1 2 3 ... 7 8 9 10 * 11 12 [13] ... 30 31 32
  • 1 2 3 ... 10 11 12 13 * 14 15 [16] ... 30 31 32

(* current page, [] = click)

It seems that most of the work goes to the middle of the stack.

  • How can I extend Kaminari to go to page 16 by pressing the space bar (...)?
  • Is it possible to extend Kaminari to show the middle from the very beginning?

1 2 3 4 ... 15 16 17 ... 30 31 32

+5
source share
2 answers

You can play with the parameters of the internal and external windows ( link ), but I do not think this will solve your problem.

As @Michal Szyndel mentioned in the comment, you will need to use a generator ( rails g kaminari:views THEME note: you can pass -e to generate different template languages). After you have generated the files, you can partially edit the "paginator" using some custom logic. To get into this, how to do it, Ryan railscast (starting at 4:53)

I hope this allows you to get quite a lot, because since this middle window works when you are not at the beginning or end of your pagination, it will depend on the size of the windows and what you want. (for example, if you have an external window of 3 and an internal window of 2 with 50 pages, what do paginator links look like when you are on page 15?)

If you need more help, just reply with a comment and I will answer more specifically.

+1
source

Extending elements of the kaminari view is quite simple. You need to set up the pagination assistant, https://github.com/amatsuda/kaminari#customizing-the-pagination-helper

In particular, and if you use ERB, you want to edit your new app/views/kaminari/_gap.html.erb .

 <% url,data = url.split('?') url += '?page=' + (num_pages/2) %> <span class="page gap"> <%= link_to_unless page.current?, page, url %> </span> 

This creates a link to your middle (really num_pages/2 page) page.

+1
source

Source: https://habr.com/ru/post/1240327/


All Articles