Rails_admin, change order of columns in list
Asked Answered
B

3

6

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.

Blumenfeld answered 24/11, 2015 at 8:29 Comment(0)
M
2

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!

Maressa answered 24/11, 2015 at 13:52 Comment(1)
It prompts "undefined method `defined' for nil:NilClass" if used with a dynamic fieldChisel
R
3

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.

Rosenberger answered 9/4, 2021 at 16:10 Comment(0)
M
2

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!

Maressa answered 24/11, 2015 at 13:52 Comment(1)
It prompts "undefined method `defined' for nil:NilClass" if used with a dynamic fieldChisel
M
0

In app/admin/item.rb you can do this.

index do column :Name column :id column :created_at end

This will give you column with Name, id and created_at.

Martinsen answered 24/11, 2015 at 8:49 Comment(4)
will it affect to list action ?Blumenfeld
No it wont affect your list action,its only in admin side.i hope you have admin/list.rb file where you can add following code.Martinsen
Is it activeadmin gem you are mentioning? I use rails_admin gemBlumenfeld
if so than you can use this way. RailsAdmin.config do |config| config.model 'Team' do list do field :name field :created_at end end endMartinsen

© 2022 - 2024 — McMap. All rights reserved.