Using latest rails_admin from gem 'rails_admin', :git => 'https://github.com/sferik/rails_admin.git'
config.model Post do
sort_reverse false # or true anyway sorting goes ASC
exclude_fields :created_at, :updated_at
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
For now, you can use
configure :weight do
but either the implementation or the documentation in Wiki should be fixed..
Thanks, that's work fine, for one sort field,
But what if you need to sort not only by weight, but also by date?
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.
sort_by 'position DESC, name ASC, code ASC, id'
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
The documentation in Wiki has been fixed to meet implementation.
@adriansalceanu - It looks like what rails admin is doing is equivalent to
Adding the following, and leaving off the last ASC working for me:
sort_by 'event_id DESC, position'