zlx / tabletastic

A smart table builder for Rails collections

Home Page:http://jgdavey.github.com/tabletastic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tabletastic 使用

table_for

example:

table_for @admin_users, html: { class: '' } do |t|
  ...
end
  • 配置 Tabletastic.default_table_html 来指定 table 的默认样式

cell

example:

table_for @admin_users do |t|
  t.cell(:login, width: '20%', sort: true, cell_html: { }, heading_html: {}) { |user| user.great_login }
end
  • width: 指定 head 的宽度,对应于 th 里面的 width
  • cell_html: 指定 tbody 里面 td 的样式
  • heading_html: 指定 thead 里面 td 的样式
  • sort: 集成类似于 ransack 的 sort_link,传递 {"q": {"s": "login asc"}} 参数
  • block: 替换掉默认显示的内容 user.login

操作

对于 actions 采用 block 的形式

<%= t.cell(:action) do |user| %>
  <%= render_edit_link(user) %>
  <%= render_block_user_link(user) %>
<% end %>

已知的 Bug

<%= t.cell(:comments_count) { |q| q.comments.count } %>

这样会显示不出结果,要改成

<%= t.cell(:comments_count) { |q| q.comments.count.to_s } %>

About

A smart table builder for Rails collections

http://jgdavey.github.com/tabletastic/

License:MIT License


Languages

Language:Ruby 98.9%Language:Logos 1.1%