Sort a table_for in rails activeadmin

后端 未结 3 909
谎友^
谎友^ 2021-02-19 15:52

In an active admin show page, I\'ve got two panels, the first being the primary record, the second being associated info (by has_many) so show looks like this:

3条回答
  •  孤街浪徒
    2021-02-19 16:11

    With rails 4.2, based on @idrinkpabst, I did the following:

    table_for group.devices.order(
      # Support for column name with underscore
      # Support "no sort param"
      (params[:order] ? params[:order] : '').gsub('_asc', ' asc').gsub('_desc', ' desc')
    ), sortable: true do
      # Directly using symboles and not using sortable:
      column :presence
      column :serial_number
      column :apk_version
      column :firmware_version
    end
    

    It's a more robust version:

    • allows column name with underscore
    • support "no sort param"
    • works with rails 4.2

提交回复
热议问题