Use rails_admin for Sorting fields

Is there a way to sort the fields in rails admin. Not like sorting to view, but sorting in model?

For better understanding:

You have a list of items.

  • Arthur Dent [Sort ID: 1]
  • Ford Prefect [Sort ID: 2]
  • Tricia Marie McMillan [Sort ID: 3]

Now you rearrange them as rails_admin:

  • Tricia Marie McMillan [Sort ID: 1]
  • Arthur Dent [Sort ID: 2]
  • Ford Prefect [Sort ID: 3]

And the Sort ID automatically switches.

I hope you understand what I mean, a little hard to describe

+4
source share
1 answer

By default, rows are sorted by id in reverse order. You can change the default behavior to two methods: sort_by and sort_reverse

RailsAdmin.config do |config| config.model Player do list do sort_by :name field :name do sort_reverse false end end end end 

You can find more information here: https://github.com/sferik/rails_admin/wiki/List

+1
source

Source: https://habr.com/ru/post/1438889/


All Articles