1

我在 Rails 3 站点中使用will_paginate进行分页。我希望能够单击每个输出字段的表头(例如“名称”、“创建于”)并在该字段上排序结果。能够再次单击以进行反向排序也很好。有什么东西可以很好地与 will_paginate 一起订购吗?我可以只使用 will_paginate 来做到这一点吗?

我使用的表格格式非常通用:

<%= will_paginate %>
<table>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Updated</th>
    </tr>   
    <% @shops.each do |shop| %>
    <tr>
        <td><%= shop.id %></td>
        <td><%= shop.name %></td>
        <td><%= shop.updated_at.strftime("%a %b %d %H:%M ") %></td>
    </tr>
    <% end %>
</table>
<%= will_paginate %>
4

3 回答 3

2

您会在这里找到您所期望的所有内容:http ://railscasts.com/episodes/240-search-sort-paginate-with-ajax

于 2013-01-21T11:03:20.763 回答
0

我在用

gem "meta_search"

与 will_paginate

Github 项目站点

Railscasct #251 元位置和元搜索

索引控制器示例

@search =  Customer.search(params[:search])
@customer = @search.paginate(:page => params[:page], :per_page => 50)

并查看示例

<th><%= sort_link @search, :name%></th>
<th><%= sort_link @search, :surname %></th>
<th><%= sort_link @search, :address %></th>
于 2013-01-21T12:27:24.640 回答
-2

备择方案:

1)使用强大的jquery插件:

使用 jquery 插件,排序和分页变得简单。

这里有一个强大的 jquery 插件。

jQuery Tablesorter的更多内容:分页和排序变得简单。

2)可排序的表列:

如果你想在没有 jquery 插件的情况下进行排序,那么你会在这里得到你想要的一切。上述方法添加了通过单击标题按升序或降序对表格列进行排序的功能。

于 2013-01-21T11:02:01.547 回答