Kaminari ajax pagination does not update paginate

I use pagination in rails3 using kaminari stone.

I followed this code from github https://github.com/amatsuda/kaminari_example/commits/ajax

unfortunately the following code

  jQuery ('# paginator'). html ('<% = escape_javascript (paginate (@recipes,: remote => true) .to_s)%>');

doesn't seem to work.

my javascript for what to do, what the user chooses for the page,

  jQuery ('a', 'nav.pagination'). click (function () {
          // get the page value from href
           var page = jQuery (this) .attr ('href'). replace ('/ home / index? page =', '');
           jQuery.getJSON ('? page =' + page, function (data) {
                  for (var r in data) {
                    results.push (data [r]);
           });
               showResults (results, (page-1) * 10);
               jQuery ('# paginator'). html ('<% = escape_javascript (paginate (@recipes,: remote => true) .to_s)%>');
   });

The showResults function is launched via JSON and creates a bunch of html elements. Everything works just fine, except that pagination does not refresh to show the current page when the results are reloaded.

I have no errors in firebug, I use Rails 3 with ruby ​​192.

+4
source share
2 answers

Are you sure you have the #paginator element for paginator in HTML? I mean, does the following code return in Firebug?

jQuery('#paginator') 
+1
source

To update the result and paginate, you need to update both at a time. Paginate AJAX sends the request as JS, in order to process them, you must have the action.js.erb file inside the view folder. Do two things here.

1) Update the result

 $("#issues").html("<%= j render(:partial => 'recipes') %>"); 

2) Update Paginate

 $('.pagination').html('<%= escape_javascript(paginate(@recipes, :remote => true).to_s) %>'); 

Find the appropriate page attribute to refresh the page. This will update the paginate results and runtime.

0
source

Source: https://habr.com/ru/post/1346306/


All Articles