Skip to content

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

License

Notifications You must be signed in to change notification settings

JuannFerrari/sort_n_params

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages