Welcome Guest, Not a member yet? Register   Sign In
Pagination - show number results on current page
#1

Hi,
I am using the pagination library to create some overviews.
On these pages, I would like to show how many results there are on the current page.
For example:
Users: 15 of 25
I can use $pager->getTotal for the total amount, but there doesn't seem to be a method to show the number of results on the current page.
Am I missing something???
I'm sure I'm not the only one who needs this.
Reply
#2

See https://codeigniter4.github.io/userguide...g-the-view
getPageCount()
Reply
#3

This method returns total number of pages.

I need the number of results on the current page.
Reply
#4

count($rows) ?
Reply
#5

(02-05-2022, 05:07 AM)sjender Wrote: This method returns total number of pages.

I need the number of results on the current page.

What do you mean?
getCurrentPageNumber() ?
Reply
#6

I believe he is wanting something like:
"Showing 1 to 10 of xx results" on each page shown.
The best example for this is DataTables, I suppose.
If plan A fails, relax... the alphabet is 26 letters
Reply
#7

Yes. That's what I mean.
But there doesn't seem to be a method for that.
Surely I can work my way around it. But it would be nice if there was a method within $pager for that.
Reply
#8

Ok guy's this is how I' am doing it in my new blog I' am working on.

PHP Code:
<!-- Pagination Views/pagination.php include this view in your view or layout. -->
<
div class="pagination justify-content-center mb-4">
    <?php if ( ! empty($pager)) :
        //echo $pager->simpleLinks('group1', 'bs_simple');
        echo $pager->links('group1''bs_full');
    endif ?>

    <!-- Bootstrap 5.1.3 code to show page 1 of 4 total pages using a button. -->
    <div class="btn-group pagination justify-content-center mb-4" role="group" aria-label="pager counts">
        &nbsp;&nbsp;&nbsp;
        <!-- NOTE: $currentPage and $totalPages are set in the Controllers $data and passed in to the view. -->
        <button type="button" class="btn btn-light"><?= 'Page '.$currentPage.' of '.$totalPages?></button>
    </div>
</div> <!-- End of pagination -->

// Controller
$data = [
    'pager'      => $posts->pager,
    'currentPage' => $posts->pager->getCurrentPage('group1'),
    'totalPages'  => $posts->pager->getPageCount('group1'),
]; 

Make sure you read the comments in the code.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

It looks like I am not explaining my issue very well Smile.

I will explain it in more detail (because the example InsiteFX has provided, shows the number of pages, that's not what I mean).

Imagine making an overview of al registered users of the site.
In this example there are 55 users.

I will use the paginator service and I set the number of results per page on 20....

So, the first page wil have 20 users on it.
The second also 20
But the third only 15.

In the topbar of the table I want to show this number (users on this specific page).

So.......

Page 1 should have "Users: showing 20 of 55"
Page 2 should have "Users: showing 20 of 55"
Page 3 should have "Users: showing 15 of 55"

The total amount (55) is not a problem, that is $pager->getTotal().
But the first one (20, 20, 15) is the one I'm looking for..

I hope I have made my issue somewhat more understandable like this?
Reply
#10

That's some thing your going to have to write yourself, there are no method's for that.

Maybe create a helper for it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB