Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails_admin, change order of columns in list

In rails_admin list shows all available columns of model according to how columns are ordered in database:

pic

However, I want different order in list page. I want first name and then other fields in table.

Is it even possible? There are no mentions in documentation of rails_admin about it.

like image 636
Mr.D Avatar asked Nov 24 '15 08:11

Mr.D


2 Answers

The documentation has changed. Create rails_admin folder in initializers. Add an .rb file with your model name to that folder: config/initializers/rails_admin/.

Then add columns that you want to leave in the order you want them to be shown.

RailsAdmin.config do |config|
  config.model 'YourModelName' do
    list do
      field :name
      field :version
    end
  end
end

This would show only "name" and "version" columns in the list view.

like image 111
inmydelorean Avatar answered Oct 20 '22 18:10

inmydelorean


You can read about ordering of fields here: https://github.com/sferik/rails_admin/wiki/Fields#inclusion

In case your model is called User, create a new configuration file config/initializers/rails_admin/user.rb

with the following content:

if User.table_exists?
  RailsAdmin.config User do
    list do
      # simply adding fields by their names (order will be maintained)
      include_fields :name, :id, :created_at, :updated_at, :version, :shopping_malls
    end
  end
end

Let me know if this works out!

like image 31
sourcx Avatar answered Oct 20 '22 16:10

sourcx