CakePHP 3 AJAX with Pagination

914 Views Asked by At

I am new to CakePHP. I have installed CakePHP 3.2.10.

I have implemented simple AJAX calls. I have also implemented pagination in normal view.

Now I want to show records, loading with AJAX and using pagination.

Can anyone guide me how to go about doing this?

I have referred to the cookbook but did not get proper information.

Do I create a normal action and view with pagination code ?

1

There are 1 best solutions below

0
On

Simply, you can use liveQuery Javascript library. you can download from here

  1. And add this library code in your CakePHP template layout in
  2. Wrap your listings and pagination links in div tag apply id="wrapper".
  3. add this function in common javascript code which must be load in page end before end of body tag

Add Below Code in Javascript

function ajaxPageLoader(request_url) {
        console.log("Content loading from : "+request_url);
        $("#wrapper").load(request_url + " #wrapper", function() {
            window.history.pushState({}, "", request_url);
            console.log("Content loaded");
        });
    }
$(document).ready(function(){
       $('your_pagination_link_selector').livequery(function() {
            $(this).unbind('click').bind('click', function(e) {
                e.preventDefault();
                ajaxPageLoader($(this).attr('href'));
                return false;
            })
       });
    });