Juergen Posted November 17, 2023 Share Posted November 17, 2023 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). I am on the first page - everything ok I 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 More sharing options...
bernhard Posted November 17, 2023 Share Posted November 17, 2023 I've never used that myself but searching the core for "->renderPager(" returns 3 results, so if you look at one of those you should see how Ryan did it and that should work for you as well ? 1 Link to comment Share on other sites More sharing options...
Juergen Posted November 17, 2023 Author Share Posted November 17, 2023 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 More sharing options...
Juergen Posted November 17, 2023 Author Share Posted November 17, 2023 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: Page 2: 2 Link to comment Share on other sites More sharing options...
szabesz Posted November 18, 2023 Share Posted November 18, 2023 Related tutorial is located here: 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now