sort_reverse doesn't work #1181

Open
kor6n opened this Issue Jun 3, 2012 · 6 comments

Comments

Projects
None yet
3 participants

kor6n commented Jun 3, 2012

Using latest rails_admin from gem 'rails_admin', :git => 'https://github.com/sferik/rails_admin.git'

  config.model Post do
    list do
      sort_by :weight
      sort_reverse false # or true anyway sorting goes ASC
      exclude_fields :created_at, :updated_at
    end
    weight 203
  end

kor6n commented Jun 4, 2012

sort_by "weight " - (with space on the end) turns to needed SQL query: ORDER BY posts.weight desc LIMIT ...
sort_by :weight - turns to: ORDER BY posts.weight asc LIMIT ... independently of sort_reverse true / false

Collaborator

mshibuya commented Jun 13, 2012

Confirmed.
For now, you can use

  list do
    sort_by :weight
    configure :weight do
      sort_reverse true
    end
  end

but either the implementation or the documentation in Wiki should be fixed..

kor6n commented Jun 18, 2012

Thanks, that's work fine, for one sort field,
But what if you need to sort not only by weight, but also by date?

@ghost

ghost commented Aug 15, 2012

I had the same problem.
If you want to sort by multiple columns, pass the param to sort_by as a string - RailsAdmin will (almost) happily chew it.

Ex:

list do
  sort_by 'position DESC, name ASC, code ASC, id'
end

Unfortunately, RailsAdmin decided to sort the last column DESC - so I've put in multiple explicit ASC sorts and another column, at the end, which I didn't care about. The executed query was:

SELECT `countries`.* FROM `countries` ORDER BY countries.position DESC, name ASC, code ASC, id desc LIMIT 30
Collaborator

mshibuya commented Apr 25, 2013

The documentation in Wiki has been fixed to meet implementation.

@adriansalceanu - It looks like what rails admin is doing is equivalent to
"#{table_name}.#{YOUR_INPUT.to_s} desc"
Adding the following, and leaving off the last ASC working for me:

list do
  sort_reverse false
  sort_by 'event_id DESC, position'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment