
Security News
npm Phishing Email Targets Developers with Typosquatted Domain
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.
SortingTableFor is a Rails TableBuilder made to easily create table or sort a table. The syntax is simple to write and easy to read.
In Rails 3, add this to your Gemfile.
gem "sorting_table_for", '> 0.2.1'
In Rails 2, add this to your environment.rb file.
config.gem "sorting_table_for", '0.2.2'
Alternatively, you can install it as a plugin.
rails plugin install git://github.com/arkes/sorting_table_for.git
To create a quick table
<% sorting_table_for @users do |table| %>
<%= table.headers %>
<%= table.columns %>
<% end %>
will render
<table>
<thead>
<tr>
<th class='cur-sort-not'><a href='/my_link?table_sort[username]=asc'>...</a></th>
<th class='cur-sort-not'><a href='/my_link?table_sort[firstname]=asc'>...</a></th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan='4' class='total-entries'>Total Entries: 2</td>
</tr>
<tr>
<td>Test</td>
<td>Myname</td>
<td><a href='/users/1/edit'>Edit</a></td>
<td><a href='/users/1'>Delete</a></td>
<tr>
</tbody>
</table>
column and header can be called with a list
<% sorting_table_for @users do |table| %>
<%= table.headers :username, :firstname, :lastname %>
<%= table.columns :username, :firstname, :lastname %>
<% end %>
On columns you can get the current object of your collection. You can give to column or header whatever you want: symbol, string, image, ...
<% sorting_table_for @users do |table| %>
<%= table.headers do %>
<%= table.header :username %>
<%= table.header :firstname %>
<%= table.header image_tag('rails.png') %>
<% end %>
<%= table.columns do |user| %>
<%= table.column :username %>
<%= table.column user.firstname %>
<%= table.column 'exemple' %>
<% end %>
<% end %>
column and header can be called with a block
<% sorting_table_for @users do |table| %>
<%= table.headers do %>
<%= table.header do %>
<%= image_tag('rails.png') %>
<% end %>
<% end %>
<%= table.columns do |user| %>
<%= table.column do %>
<%= user.username.downcase %>
<% end %>
<% end %>
<% end %>
You can set a footer to the table, it can be called with a list or a block
<% sorting_table_for @users do |table| %>
<%= table.footers :footer %>
<% end %>
-- equivalent --
<% sorting_table_for @users do |table| %>
<%= table.footers do %>
<%= table.footer :footer %>
<% end %>
<% end %>
Create a tag caption to set a title to the table, it can be called with or without a block
<% sorting_table_for @users do |table| %>
<%= table.caption 'my title' %>
<% end %>
Options for sorting table for
Exemple
<% sorting_table_for @users do |table| %>
<%= table.headers do %>
<%= table.header :username %>
<%= table.header :price, :sort => false %>
<%= table.header :created_at %>
<%= table.header 'today' %>
<% end %>
<%= table.columns do |user| %>
<%= table.column user.username %>
<%= table.column user.price, :as => :currency %>
<%= table.column user.created, :as => :date %>
<%= table.column DateTime.now, :as => :datetime, :format => :short %>
<% end %>
<% end %>
Exemple with action
<% sorting_table_for @users do |table| %>
<%= table.headers do %>
<%= table.header :username %>
<%= table.header :action => :edit %>
<% end %>
<%= table.columns do |user| %>
<%= table.column user.username, :action => :show %>
<%= table.column :action => :edit %>
<% end %>
<% end %>
Exemple with html
<% sorting_table_for @users, :html => { :class => 'my_table' } do |table| %>
<%= table.headers :html => { :class => 'my_headers', :title => 'column !' } do %>
<%= table.header :username :html => { :class => 'header_username' } %>
<%= table.header :firstname :html => { :title => 'hello price' } %>
<% end %>
<%= table.columns :html => { :class => 'my_columns' } do |user| %>
<%= table.column :username :html => { :class => 'column_username' }%>
<%= table.column :firstname :html => { :title => "it's #{user.firstname}" } %>
<% end %>
<% end %>
SortingTableFor can use your namespace
<% sorting_table_for [:admin, @users] do |table| %>
<%= table.headers %>
<%= table.columns %>
<% end %>
To add sort in your query, you just have to add sorting_table in your query
def index
@users = User.sorting_table(params).all
end
to add a default sorting
def index
@users = User.sorting_table(params, :username).all
end
-- or --
def index
@users = User.sorting_table(params, :username, :desc).all
end
You can add ajax on sorting
<% sorting_table_for @users, :sort_remote => true do |table| %>
<%= table.headers %>
<%= table.columns %>
<% end %>
You can add ajax on links
<% sorting_table_for @users, :link_remote => true do |table| %>
<%= table.headers %>
<%= table.columns %>
<% end %>
There are some options that you can modify in your initiatilizer
see the initializer file exemple for more explanation
Copyright (c) 2010 arkes (Thomas Floch), released under the MIT license
FAQs
Unknown package
We found that sorting_table_for demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.
Security News
Knip hits 500 releases with v5.62.0, refining TypeScript config detection and updating plugins as monthly npm downloads approach 12M.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.