Jump to content

MarkupPagerNav does not change the active status of the current page [SOLVED]


Juergen
 Share

Recommended Posts

Hello @all

I am struggeling for a while to get it working, but I do not succeed.

Description:

I have a PaginatedArray containing a lot of comments and therefore I have created a new custom page inside the admin which contains all the comments inside a AdminTable.

Now I want to add a pagination below the table, to show only a certain amount of comments per page. To render the pagination I have included the following code:

echo $allComments->renderPager(); // $allComments is the PaginatedArray

This outputs the pager and the redirection to page1, page2 and so on works, but the active state of the pager button will always stay on the first button (the pager button number 1 has always the red background color, even if another page different from 1 is loaded).

image.png.6334fe2f6c1a4899eab13c6afcab75d9.pngI am on the first page - everything ok

image.png.7f492467c758ef107e307fc3c9dc85ce.pngI am on the second page, but number 1 is still active

I have also tried to change the current page manually:

$pager->setPageNum(2);

Source: https://processwire.com/api/ref/markup-pager-nav/set-page-num/

But this does not work too!

Can someone show me a working example with pagination and a PaginatedArray?

Thanks in advance!

 

Link to comment
Share on other sites

Thanks for the hint @bernhard!

I will study those pieces of code. There some examples inside the docs, but they all use a pages->find(method) including a selector with a limit (fe limit=10) for the SQL query to get a page array. Maybe including a limit will do the trick. I will see.

Link to comment
Share on other sites

I have found the solution inside the FieldtypeComments.module from Ryan:

 * Unlike $pages->find(), pagination of comments is not automatically tied to 
	 * $input->pageNum(). As a result, if you paginate, you should specify both 
	 * “start=n” and “limit=n” in your selector:
	 * 
	 * ~~~~~~
	 * $limit = 20;
	 * $start = ($input->pageNum() - 1) * $limit; 

So adding setStart()  and setLimit() method will solve the problem. I have only added setLimit() before.

$commentPerPage = 20; // how much comments should be displayed
$pageNum = wire('input')->pageNum();
$start = ($pageNum - 1) * $commentPerPage;
$allComments->setStart($start);

Page 1:

image.png.86badd42874e1a3975360a706b2059f3.png

Page 2:

image.png.55b5821c7b488bd03a5c3acc65abe60a.png

  • Like 2
Link to comment
Share on other sites

  • Juergen changed the title to MarkupPagerNav does not change the active status of the current page [SOLVED]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...