will_paginate分页插件有一个WillPaginate::LinkRenderer,这个用来定义分页的html输出,我们可以继承这个,从而达到自定义分页输出。
例如:我现在想去掉分页中显示的“上一页”和“下一页”,我们可以在lib中定义一个子类:
class CustomPaginationRenderer < WillPaginate::LinkRenderer
def to_html
links = @options[:page_links] ? windowed_links : []
html = links.join(@options[:separator])
@options[:container] ? @template.content_tag(:div, html, html_attributes) : html
end
end
页面上
<%= will_paginate @items, :renderer => 'CustomPaginationRenderer' %>
而我正想达到的一需求是在原来分页显示的基础上,加上一些分页信息,如每页显示多少条数据,一共有多少页等:
class PaginationDetailLinkRenderer < WillPaginate::LinkRenderer
def to_html
links = @options[:page_links] ? windowed_links : []
links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
links.push page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label])
html = links.join(@options[:separator])
html = "每页显示<b>#{@collection.per_page}</b>条数据,共有<b>#{total_pages}</b>页, 共有<b>#{@collection.total_entries}</b>条数据" + html
@options[:container] ? @template.content_tag(:div, html, html_attributes) : html
end
end
效果:
参考资料:
http://thewebfellas.com/blog/2008/8/3/roll-your-own-pagination-links-with-will_paginate
http://zilkey.com/2008/3/16/rendering-will_paginate-links-without-previous-and-next-buttons
分享到:
相关推荐
will_paginate分页插件 博文链接:https://foxgst.iteye.com/blog/168489
will_paginate-bootstrap, 将 Twitter Bootstrap 分页组件与will_paginate集成 will_paginate-bootstrap不再维护我不再使用 Bootstrap 来使用 Rails,所以不幸的是,我不再接受请求请求或者维护这个库。 为了发布你...
rails 分页插件will_paginate 2.2.2
rails 分页插件will_paginate 2.1.0
rails 分页插件will_paginate
因为需要安装svn比较麻烦,就直接手工下载了
NULL 博文链接:https://liuyi-act-buaa-edu-cn.iteye.com/blog/506503
cd will_paginate_endless_scroll_example 安装依赖: bundle install 迁移和种子数据库: bundle exec rake db:migrate db:seed 就是这样,它准备好了。 跑步: 像普通的 rails 应用程序一样运行: rails s ...
Rails Engine扩展了样式以匹配Twitter的 4工具包中的分页样式约定。 安装 添加到您的Gemfile: gem 'will_paginate-bootstrap4' 用法 <%= will_paginate @clients, renderer: WillPaginate::ActionView::...
jQuery paginate分页导航插件ajax分页代码 jQuery paginate分页导航插件ajax分页代码 jQuery paginate分页导航插件ajax分页代码
新版本的will_paginate已经抛弃了这样的做法,转而使用gem的方式,本文通过建立一个名为foobar的应用来了解一下will_paginate的用法。 ============================== C:\>rails foobar -d mysql C:\>cd foobar C:\...
will_paginate will_paginate是一个分页库,与Ruby on Rails,Sinatra,Hanami :: View,Merb,DataMapper和Sequel集成。 安装: ## Gemfile for Rails 3+, Sinatra, and Merbgem 'will_paginate' , '~> 3.1.0' 有关...
paginate(每页数量,是否简洁分页,分页参数) 使用方式 $list = db('user')->paginate(10); 自定义参数传参 $list = db('user')->paginate(10,false,['query'=>array('id' => $id)]); 其它参数 // 总数据 $this->...
mysql_paginate_query #执行分页支持的SQL语句 输入: sql #要执行的业务SQL语句 offset #偏移量(必须按照count对齐, 即可以被count整除), 范围: [0, 无穷] count #读取条数, 范围: [1, 无穷] prev_id #标记上...
will_paginate will_paginate是一个分页库,与Ruby on Rails,Sinatra,Hanami :: View,Merb,DataMapper和Sequel集成。 安装:##用于Rails 3 +,Sinatra和Merb的Gemfile gem'will_paginate','〜> will_paginate ...
资源分类:Python库 所属语言:Python 资源全名:mkdocs_paginate_plugin-0.0.3-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
有几种类型的分页项: 上一页一般页面当前页面下一页差距仅当可以转到这些页面时才会显示上一页项目和下一页项目。 常规页面项目包含指向特定页面的链接。 第一页和最后一页的项目始终可见。 当前页面项目没有链接...