Kaminari with AJAX, unable to paginate

自作多情 提交于 2019-12-12 03:34:14

问题


I've followed the AJAX Kaminari example here: https://github.com/amatsuda/kaminari_example/tree/ajax

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.

I found a similar problem, however the solution remains unanswered: kaminari ajax pagination not updating the paginate

I can verify that I am using the #paginator element.

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>

at the end of the of my html.erb file.

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!

Edit: I am able to right-click the pagination links and open them to another tab. Clicking on them still doesn't do anything.

EDIT:

I wanted to add that I'm using Twitter Bootstrap. I noticed that if I set in my controller

format.html { render :layout => false }

Then I open one of the pagination links to another page, I can successfully paginate. I am using the Kaminari bootstrap theme however...


回答1:


I didn't see a place to add a comment, so this is not a real answer.

Do only render the table with AJAX? Is the partial part of another page? Or is a stand alone view?

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>


来源:https://stackoverflow.com/questions/14201895/kaminari-with-ajax-unable-to-paginate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!