简体   繁体   中英

To hide "..." used in the will_paginate function on Rails

I'm using will_paginate due to the volume of values, but I can't figure out how to hide the "..." portion and the page numbers after. This is what I currently have: 在此处输入图片说明

This is what I'd like to have:

< 1 2 3 4 >
clicking next would give me < 2 3 4 5 > (Notice how in both, we don't see the ".." followed by 95 96 97.)

Any idea how this can be done? Here is the relevant HTML:

<div class="pagination full">
  <span class="previous_page disabled">&lt; 前へ</span>
  <em class="current">1</em>
  <a rel="next" href="/student/search?page=2">2</a>
  <a href="/student/search?page=3">3</a>
  <a href="/student/search?page=4">4</a>
  <a href="/student/search?page=5">5</a>
  <a href="/student/search?page=6">6</a>
  <a href="/student/search?page=7">7</a>
  <a href="/student/search?page=8">8</a>
  <a href="/student/search?page=9">9</a>
  <span class="gap">…</span>
  <a href="/student/search?page=95">95</a>
  <a href="/student/search?page=96">96</a>
  <a href="/student/search?page=97">97</a>
  <a class="next_page" rel="next" href="/student/search?page=2">次へ &gt;</a>
</div>

Thanks!

You need to make a custom renderer for will_paginate . The will_paginate helper accept a parameter renderer like this:

<%= will_paginate(@users, :renderer => UserPaginationRenderer) %>

You just need to implement the UserPaginationRenderer yourself, with your own rules, like showing only 4 links and so on. There is plenty of information and articles about this:

https://thewebfellas.com/blog/roll-your-own-pagination-links-with-will_paginate
https://www.tachyonstemplates.com/2017/custom-renderer-will-paginate/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM