0.0
No commit activity in last 3 years
No release in over 3 years
This gem provides helpers for building sortable column headings in a table with links. It also monkey patches (for better or for worse) ActiveRecord and provides a more succinct api for sorting based on the table column links. It is the intention to expand this API to provide default and secondary sorts. It's very basic but I have built this functionality enough times to warrant gemification Features via pull requests welcome
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 3.1
 Project Readme

Tablesorter

==============================================================================================

View Helpers

sortable_column_headings(columns, options={})

so

<tr>
  <%= sortable_column_headings(['name', 'age']) %>
</tr>

gives

<tr>
  <th><a href="?dir=asc&sort=name">Name<span></span></a></th>
  <th><a href="?dir=asc&sort=age">Age<span></span></a></th>
</tr>

When selected the link will be given a class of selected and either asc or desc. You can use this to style the span with an arrow.

Styling

If you want different headings to be displayed in your table headings use translations under the tablesorter namespace.

en:
  tablesorter:
    age: 'Age (in years)'

Active Record

tablesort method

table_sort(sort_attr, dir, default_attr, default_dir)

eg

Person.scoped.table_sort(params[:sort], params[:dir], 'id', 'asc')

This project uses the MIT-LICENSE.

TODO

  • Test!
  • Add a note about translations for table headings
  • maybe extend api of helper method so you can pass a hash rather then an array
  • Improve readme and add some default css to show arrow styling
  • twitter bootstrap arrows option
  • Secondary sort
  • Dont call order if no params passed
  • mongoid?
  • datamapper?