This is regarding the following jQuery Pagination code: https://github.com/gbirke/jquery_pagination/blob/master/src/jquery.pagination.js
I can get it to run fine as the current code should, but wondered if anyone has any suggestions to essentially make the pagination show the pages in groups of 7, so they can go from page 1-7 and it only shows those pages in the navigation. Then when they go to page 8, it will show the pages 8-14 and so on.
Rather than just moving up to show 1-7, 2-8, 3-9 etc like shown in this example: https://i.gyazo.com/5afa6e66e7e95f973d83191f45d8296e.mp4
I understand it may be fairly difficult, but I may be wrong!
Bonus would be being able to jump in pages of 7 at a time, but think I can sort that fine once this issue is resolved.
Any suggestions much appreciated.
Thanks a lot!
The functionality you want is not what implemented in that plugin. One way or another, you will need to modify the plugin code meet your requirements. You could fork the project and create your own modified implementation, or you could overwrite the code in your page after the plugin has been loaded. I will give you an example of the second alternative.
Taking a peek at the plugin source code, we find this helpful comment:
This is likely where the code is that we are interested in because the comment tells us that this is where the start and end pagination links are calculated. This comment is applied to a method called
getInterval
which belongs to theprototype
of a constructor function calledPaginationCalculator
which the plugin defines and attaches to the global jQuery object ($
).In order for us to modify the start and end links we will need to overwrite this method. The source shows us that this method accepts a single parameter,
current_page
and returns an object with two properties,start
andend
(despite the fact that the comment above the method says that this method returns an Array).We know that we want
start
to be a multiple of thenum_display_entries
number with which we configure our plugin instance (ex.,7
). Ourstart
can be0
,7
,14
, etc., depending on which chunk of 7 ourcurrent_page
belongs to. Also, we know that ourend
must be 7 more than ourstart
, unless this produces anend
that is greater than our total number of pages, in which caseend
should be equal to the total number of pages. We can obtain the total number of pages using another prototype method of thePaginationCalculator
constructor,numPages
.The following code will satisfy our requirements:
I have created a JS Fiddle demo for reference.