Reputation: 7585
Does anyone know any good gems that can be used to create tables for Ruby on Rails apps. I am looking for something that has built in sorting, AJAX searches, etc.
Upvotes: 3
Views: 4054
Reputation: 3141
check out thoughtbot's sortable_table: http://github.com/thoughtbot/sortable_table
Pop 'sortable_attributes' in your controller:
class UsersController < Admin::BaseController
sortable_attributes :name, :email, :age, :group => "groups.name"
def index
@users = User.paginate :page => params[:page], :order => sort_order
end
end
Pop some helpers in your view:
<h1>Users</h1>
<table>
<tr>
<%= sortable_table_header :name => "Name", :sort => "name" %>
<%= sortable_table_header :name => "Email", :sort => "email" %>
<%= sortable_table_header :name => "Age", :sort => "age" %>
<%= sortable_table_header :name => "Group", :sort => "group" %>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= html_escape(user.name) %></td>
<td><%= html_escape(user.email) %></td>
<td><%= html_escape(user.age) %></td>
<td><%= html_escape(user.group.name) %></td>
</tr>
<% end %>
</table>
done :)
UPDATE (June 2012): The owner of this gem has marked it as deprecated and unsupported.
Upvotes: 3
Reputation: 8305
You also could try datagrid gem that can create table with sortable columns and filters.
Upvotes: 3