Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails Tables Gem

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.

like image 279
Splashlin Avatar asked Dec 11 '25 00:12

Splashlin


2 Answers

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.

like image 75
Gazza Avatar answered Dec 13 '25 13:12

Gazza


You also could try datagrid gem that can create table with sortable columns and filters.

like image 44
Bogdan Gusiev Avatar answered Dec 13 '25 13:12

Bogdan Gusiev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!