2013-03-02 69 views
1

的儀表板如何定製比方說,我有一個ActiveRecord的查詢:自定義查詢排序表中ActiveAdmin

User.select('name', 'created_at').all 
=> [#<User created_at: "2012-08-06 13:27:40", name: "Alice">, #<User created_at: "2012-08-06 15:41:33", name: "Bill">] 

如何通過created_at列顯示與行跨度的可分類表?

預期輸出HTML:

<table> 
     <tr> 
      <th>created_at</th> 
      <td>name</td> 
     </tr> 
     <tr> 
      <td>2012-08-06</td> 
      <td>Alice</td> 
     </tr> 
     <tr> 
      <td>2012-08-06</td> 
      <td>Bill</td> 
     </tr> 
    </table> 

回答

0

你應該閱讀文檔:http://activeadmin.info/docs/3-index-pages/index-as-table.html

假設你使用的是最新版本(0.5.1):

index do 
    column "created_at", :sortable => :created_at do |user| 
    user.created_at.strftime('%Y-%m-%d') # if the format is different that expected 
    end 
    column "name", :sortable => :name do |user| 
    user.name 
    end 
end