Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Tips and Tutorials
Pagination summary
dmurungi
June 2020
I have enabled pagination in my app and it works great. I would like to add a pagination summary with the format; "Showing x to y records of z"
Any help will be greatly appreciated.
Thank you.
Harro
June 2020
You have the start row, the number of entries, and the total (as they are all input for Pagination).
So you can add that to your view without any problems?
It is not really pagination itself, as all that does is generate the pagination navigation block.
dmurungi
June 2020
Pardon me - I just realized my question was vague. Starting over below;
In
one of my views, I have a dynamically populated table with pagination
setup and it is working correctly. A quick summary of the view;
<page header here>
<table here>
<pagination here - displayed with pagination render>
<summary here >
<page footer here>
I would like the <summary> to display "Showing 1 to 5 of 12 records" for page 1 and "Showing 6 to 11 of 12 records" for page two and so on.
Is it possible to get this information from the pagination object in the controller? If so, how?
dmurungi
June 2020
I pondered your earlier statement and achieved what I wanted with the code below.
------------------
<?php
$stpl = "Showing  %s  to  %s  of  %s  records";
$current_page = $open_tickets['pagination']->current_page;
$limit = $open_tickets['pagination']->per_page;
$total_items = $open_tickets['pagination']->total_items;
$from = (($current_page * $limit) - $limit + 1);
$to = min( ($current_page * $limit), $total_items );
echo sprintf($stpl,$from,$to,$total_items);
?>
------------------
Thank you for the guidance.
Harro
June 2020
Accepted Answer
Assuming $pagination is your pagination object:
First row: $pagination->offset;
Last row: $pagination->offset + $pagination->per_page - 1;
Total rows: $pagination->total_items;
That should do it.
And if you use the static interface and the default object, use:
\Pagination::instance()->property.
You can find the list of properties here:
https://fuelphp.com/docs/classes/pagination.html#/configuration
Harro
June 2020
Our posts crossed...
;)
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,089
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
261
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
dmurungi
June 2020
Harro
June 2020