leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 213 forks source link

How to use multiple order sql? #188

Closed wayne5540 closed 8 years ago

wayne5540 commented 9 years ago

For example, how to add query like this:

Task.order("ship_date ASC, priority ASC, updated_at DESC")

Thanks.

leikind commented 9 years ago

The plugin does not support multiple order by currently.

eikes commented 9 years ago

There is some voodoo magic you can do to use multiple order clauses:

In stead of setting the order in the initialize_grid method call you set in on the ar_options object of the grid itself.

    @task_grid = initialize_grid(Task)
    @task_grid.ar_options[:order] = "ship_date ASC, priority ASC, updated_at DESC"

This setting will be overridden if another order is set via the URL.

This is of course not part of the official API so it may break in the future...

djmolny commented 2 years ago

And sure enough, the method above doesn't work in Rails 5.2.