Search code examples
ajaxknppaginator

KNP Paginator and sortable with ajax


Is it possible to simply run the knp paginator with ajax? Is it possible at all and what is the best way to do it ?

Greetings Michael


Solution

  • Not sure if this is best solution, but I did it this way:

    $(function(){ $('#dish-select-component-canvas').on('click', "ul.pagination a" , function(e){
    $.ajax({
        type: "GET",
        url: $(this).attr('href'),
        })
        .done(function( msg ) {
            $('#dish-select-component-items').html(msg);
        });
    e.preventDefault();
    });
    

    });

    #dish-select-component-canvas is container for page. When somebody click on this canvas on link in ul.pagination (pagination is class used by knpPaginator by default as wrapper for pagination), I take href attribute of that link, and send it with ajax GET request. Result of that request goes to appropriate div (here to #dish-select-component-items). Of course you must remember to add e.preventDefault() to prevent browser from reloading the page.