任何使用 Ajax 进行排序、过滤、分页的优秀 Rails 示例/框架
Ruby on Rails 是否有任何开源(或示例)代码可以对某个模型进行过滤、排序和分页?另外,如果结果可以通过 Ajax 返回,那就太好了。我正在寻找的一个很好的例子可以在这个 Trulia 网页上看到
http://www.trulia .com/for_sale/30000-1000000_price/10001_zip/
(请注意,当过滤器被选中时,结果会在不重新加载页面的情况下更新。)
这些类型的操作(过滤、排序、分页)非常常见,以至于有人一定为此写过一些东西。我可以自己弄清楚,但我希望有示例代码或 gem 可以提供我需要的功能。再次,我希望它可以使用 jQuery 或原型通过 Ajax 来完成。
谢谢。
Is there any open source (or example) code for Ruby on Rails which can filter, sort, and paginate a certain model? Also, it would be great if the results could come back via Ajax. A good example of what I'm looking for can be seen on this Trulia web page
http://www.trulia.com/for_sale/30000-1000000_price/10001_zip/
(Note that as filters are checked off, the results are updated without a page reload.)
These kinds of operations (filter, sort, paginate) are so common that someone must have written something for this. I could figure it out myself, but am hoping there is either example code or a gem that provides the functions I would need. And again, I'm hoping it can be done with Ajax using either jQuery or prototype.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你绝对应该查看 smart_listing gem (https://github.com/Sology/smart_listing)。
除了排序之外,它还使用 kaminari 进行分页。过滤、smart_listing 还支持就地编辑。
这是演示。
You should definitely checkout smart_listing gem (https://github.com/Sology/smart_listing).
It uses kaminari for pagination and apart from sorting & filtering, smart_listing supports also in-place editing.
Here's a demo.
http://railscasts.com/episodes/240-search-sort-paginate-with-ajax< /a>
http://railscasts.com/episodes/240-search-sort-paginate-with-ajax
对于所有 ajax 内容,您可以使用 jquery,只需将事件添加到复选框,例如:
可以根据从表单接收的参数通过查询轻松完成过滤和排序
,并且您可以使用
will_paginate
( https://github.com/mislav/will_paginate) 用于分页。这是一颗伟大的宝石。您可以更新 .js.erb 文件中与控制器操作匹配的页面,或者在 ajax 调用的成功回调中更新页面(如果您使用 dataType: "html")。
For all the ajax stuff, you can use jquery and just add events to checkboxes for instance:
Filtering and sorting can be done easily with a query based on the parameters received from the form
and you can use
will_paginate
(https://github.com/mislav/will_paginate) for pagination. It's a great gem.You would either update the page in the .js.erb file matching the controller action, or in the success callback of the ajax call if you used dataType: "html".