Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activeadmin sortable by multiple columns

Is there any possibility to sort activeadmin table using multiple columns?

I've found an issue that says it is impossible now. But I wonder if anyone has implemented such functionality?

like image 271
roman Avatar asked Jul 11 '26 19:07

roman


1 Answers

I've faced same issue. Judging by source code this feature isn't supported

    def sort_order(chain)
      params[:order] ||= active_admin_config.sort_order
      if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
        column = $1
        order  = $2
        table  = active_admin_config.resource_table_name
        table_column = (column =~ /\./) ? column :
          "#{table}.#{active_admin_config.resource_quoted_column_name(column)}"

        chain.reorder("#{table_column} #{order}")
      else
        chain # just return the chain
      end
    end

But there is monkey patch solution.

like image 101
ck3g Avatar answered Jul 13 '26 11:07

ck3g