[英]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.由于值的数量,我正在使用 will_paginate,但我不知道如何隐藏“...”部分和后面的页码。 This is what I currently have:
这是我目前拥有的:
This is what I'd like to have:这就是我想要的:
< 1 2 3 4 > < 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.)单击下一步会给我 < 2 3 4 5 > (注意在两者中,我们没有看到“..”后跟 95 96 97。)
Any idea how this can be done?知道如何做到这一点吗? Here is the relevant HTML:
这是相关的 HTML:
<div class="pagination full">
<span class="previous_page disabled">< 前へ</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">次へ ></a>
</div>
Thanks!谢谢!
You need to make a custom renderer for will_paginate
.您需要为
will_paginate
制作一个自定义渲染器。 The will_paginate
helper accept a parameter renderer
like this: will_paginate
助手接受这样的参数renderer
:
<%= 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.你只需要自己实现
UserPaginationRenderer
,使用你自己的规则,比如只显示 4 个链接等等。 There is plenty of information and articles about this:有很多关于此的信息和文章:
https://thewebfellas.com/blog/roll-your-own-pagination-links-with-will_paginate https://thewebfellas.com/blog/roll-your-own-pagination-links-with-will_pagination
https://www.tachyonstemplates.com/2017/custom-renderer-will-paginate/ https://www.tachyonstemplates.com/2017/custom-renderer-will-paginate/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.