0

我有一个 Rails 应用程序,它使用 AngularJS 显示和异步更新对象列表(配置为 AngularJS 资源)。有没有一种简单的方法可以在服务器端对这个表进行分页?

4

2 回答 2

0

will_paginate gem提供了一种在 Rails 控制器和模型中对查询进行分页的方法。来自 github 自述文件:

## perform a paginated query:
@posts = Post.paginate(:page => params[:page])

# or, use an explicit "per page" limit:
Post.paginate(:page => params[:page], :per_page => 30)

## render page links in the view:
<%= will_paginate @posts %>

您可以自定义默认页面内容:

# for the Post model
class Post
  self.per_page = 10
end

# set per_page globally
WillPaginate.per_page = 10

使用 Active Record 3,您可以执行以下操作:

# paginate in Active Record now returns a Relation
Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')

# the new, shorter page() method
Post.page(params[:page]).order('created_at DESC')
于 2013-10-29T08:50:16.167 回答
0

尝试使用#ngTasty git 进行分页服务器端:https ://github.com/zizzamia/ng-tasty 文档:http: //zizzamia.com/ng-tasty/directive/table-server-side

于 2014-10-08T16:20:15.337 回答