1

I'm trying to implement a pagination plugin for my webapp, and I found a good one. But I don't understand one section of the code that's commented "Do something with the page variable". I believe this is what's preventing the pagination plugin from completely working for me.

//Pagination
$('.pagination').jqPagination({
        paged: function(page) {
        // do something with the page variable      
        }
});
Matthew
  • 27
  • 1
  • 8

1 Answers1

0

I'm the plugin creator.

What that means is within the paged callback the plugin will pass in the page variable, and within this callback you can now add whatever code you need to achieve your desired output.

If you use the following, it'll simply output the page number in the console:

$('.pagination').jqPagination({
        paged: function(page) {
                console.log(page);
        }
});

Of course, you'll likely want to do more than this, perhaps you'll want to perform an AJAX request to fetch some content:

$('.pagination').jqPagination({
        paged: function(page) {

                fetch('http://example.com/movies.json?page=' . page)
                        .then(function(response) {
                                return response.json();
                        })
                        .then(function(myJson) {
                                console.log(JSON.stringify(myJson));
                        });

        }
});

In short, you'll need to add your own code to the paged callback to do what you want it to do.

Ben Everard
  • 13,652
  • 14
  • 67
  • 96