0.01
Low commit activity in last 3 years
No release in over a year
Make your html <tables> sortables with N <th> parameters this gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 12.3.3
~> 3.0
~> 0.13.1
~> 1.30

Runtime

>= 7.0
>= 12.3.3
 Project Readme

sort_n_params

Alt Text

Sort N Params makes possible to sort your HTML tables by passing multiple parameters via HTTP's requests.

Prerequisites

  • Rails version 5.0 at least.

Installation

Inside your Gemfile add the following:

gem "sort_n_params"

Run command to set initializer

rails g sort_n_params:initializer

You can configure icon class (by default FontAwesome)

Basic Usage

In your application_record.rb add the following line:

include SortNParams::Scopes

You need to explicitly add order:[] to the list of permitted parameters, for example:

@params.permit(:page, order: [])

To sort your records, add this line:

records.sorting_order(order)

If your table's name isn't the tableize version of your model you can pass a custom table_name:

records.sorting_order(order, table_name)

Call the helper on your view:

<th><%= sortable 'id', t(:id, scope: :systems) %></th>

And that's it!

Now you can filter from another table too, just put table.column:

<th><%= sortable 'categories.name', t(:id, scope: :systems) %></th>

Remember to do the joins or eager_load in query or this feature is not work!

Additional Notes

The helper only allows two parameters: the column name to be sorted (it has to be in your database) and its title. The title may be nil, in which case the column will be titleized.

Credits

sort_n_params is maintained with the help of these contributors.

Copyright

Copyright (c) 2019 Juan Francisco Ferrari. See LICENSE for details.