Kaminari使用AJAX,无法分页 [英] Kaminari with AJAX, unable to paginate
问题描述
我在这里遵循了AJAX Kaminari示例: https://github.com/amatsuda/kaminari_example/tree/ajax
I've followed the AJAX Kaminari example here: https://github.com/amatsuda/kaminari_example/tree/ajax
我已经成功生成了partial和table.但是,按分页中的页面不会更新我的表格.实际上,按时,查询是完全相同的数据.
I've successfully generated the partial and table. However, pressing the pages in the pagination does not update my table. In fact, upon pressing, the queries are the exact same data.
我发现了类似的问题,但是解决方案仍未得到解决: kaminari ajax分页无法更新分页
I found a similar problem, however the solution remains unanswered: kaminari ajax pagination not updating the paginate
我可以确认我正在使用#paginator元素.
I can verify that I am using the #paginator element.
我做了一些不同的事情,而不是创建一个单独的js.erb文件,我添加了
Some things I did do differently were instead of creating a separate js.erb file, I added
<script>
$('#paginator').html('<%= escape_javascript(paginate(@pending_requests, :remote => true).to_s) %>');
$('#requests').html('<%= escape_javascript render (@pending_requests) %>');
</script>
位于html.erb文件的末尾.
at the end of the of my html.erb file.
此外,在视图中,我使用ajax请求在表中选择其他数据.例如,我有其在选择用户,相应的表在视图中使用AJAX呈现的select_tag.该表不是局部表,它在控制器中具有自己的视图和方法.起初我怀疑是因为这个原因,该表没有被更新.但是,如果我转到表的url,我仍然无法使用分页!
Also, in a view, I use an ajax request to select different data within the table. For example, I have a select_tag which upon selecting a user, the appropriate table is rendered using AJAX in the view. The table isn't a partial, it has its own view and method in the controller. At first I suspected that because of this, the table wasn't being updated. However, if I go to the table url, I am still unable to use pagination!
我可以右键单击分页链接并将其打开到另一个选项卡.单击它们仍然无法执行任何操作.
I am able to right-click the pagination links and open them to another tab. Clicking on them still doesn't do anything.
我想补充一点,我正在使用Twitter Bootstrap.我注意到,如果我将其设置在控制器中
I wanted to add that I'm using Twitter Bootstrap. I noticed that if I set in my controller
format.html { render :layout => false }
然后,我打开其中一个分页链接到另一页,就可以成功分页了.我正在使用Kaminari引导程序主题...
Then I open one of the pagination links to another page, I can successfully paginate. I am using the Kaminari bootstrap theme however...
推荐答案
我没有看到添加评论的地方,所以这不是真正的答案.
I didn't see a place to add a comment, so this is not a real answer.
是否仅使用AJAX渲染表格?是另一页的一部分吗?还是独立视图?
Do only render the table with AJAX? Is the partial part of another page? Or is a stand alone view?
我遇到了类似的问题(在Kaminari标签页面上,您之前的最后一篇帖子
I had a similar problem (last post before your on the Kaminari tag page link where I had the option to render the table as a partial in a show view or as a separate page. that messed things up. I ended up, like you adding a script tag, but yours in not wrapped in a document ready function, so the page might not be fully loaded. Try.
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#paginator').html('<%= escape_javascript(paginate(@pending_requests, :remote => true).to_s) %>');
$('#requests').html('<%= escape_javascript render (@pending_requests) %>');
})
</script>
这篇关于Kaminari使用AJAX,无法分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!