Welcome Guest, Not a member yet? Register   Sign In
Pagination: Add getTotalRecords and getCurrentPageRecordsTotal
#1

Hello,

This is my first post

So as we are not getting the total records and current page records in pager library to the template from pagerRenderer.php
I can workaround for total records by adding this to pagerRenderer.php :
Code:
public function getTotalRecordsCount(): int
    {
        return $this->total;
    }
but for current page records count i didn't found any solution
 
please add them so we can show bottom of the table the counts of records 

I also want to ask if there is way list S.No. (numbers) like we do within foreach loop as $i=1 and in the $i++;
sorry if there is already a solution
Reply
#2

$pager->getTotal() and $pager->getCurrentPage() ?
Reply
#3

(This post was last modified: 08-03-2023, 01:24 AM by Tanveer.)

(08-02-2023, 11:25 PM)kenjis Wrote: $pager->getTotal() and $pager->getCurrentPage() ?

doesn't work as I am talking about to use them on pager template

and we need $pager->getCurrentPageRecords(); not $pager->getCurrentPage();
Reply
#4

kenjis, we are talking about PageRenderer and not Pager. Rendering really does not contain methods. Only properties

Code:
CodeIgniter\Pager\PagerRenderer {#156 ▼
  #first: 1
  #last: 5
  #current: 3
  #total: 10
  #pageCount: 5
  #uri: CodeIgniter\HTTP\URI {#137 ▶}
  #segment: 0
  #pageSelector: "page"
}
Reply
#5

This is how I ended up doing it in my Blog.
PHP Code:
<?php
/**
 * app\Views\Pager\bs_simple.php - Bootstrap 5.3.1 Pager Template.
 * @var \CodeIgniter\Pager\PagerRenderer $pager
 */

$pager->setSurroundCount(0);
?>
<nav aria-label="Page Results">
    <ul class="pager pagination justify-content-center">
        <li <?= $pager->hasPrevious() ? 'class="page-item active"' 'class="page-item disabled"' ?>>
            <a class="page-link" href="<?= $pager->getPrevious() ?? '#' ?>" aria-label="<?= lang('Pager.previous'?>">
                <span aria-hidden="true"><?= lang('Pager.newer'?></span>
            </a>
        </li>
        <li <?= $pager->hasNext() ? 'class="page-item active"' 'class="page-item disabled"' ?>>
            <a class="page-link" href="<?= $pager->getnext() ?? '#' ?>" aria-label="<?= lang('Pager.next'?>">
                <span aria-hidden="true"><?= lang('Pager.older'?></span>
            </a>
        </li>
    </ul>
</nav>

---------------------------------------------

<?php

/**
 * app\Views\Pager\bs_full.php - - Bootstrap 5.3.1 Pager Template.
 * @var \CodeIgniter\Pager\PagerRenderer $pager
 */

$pager->setSurroundCount(2);
?>

<nav aria-label="<?= lang('Pager.pageNavigation'?>">
    <ul class="pager pagination justify-content-center">
        <?php if ($pager->hasPreviousPage()) : ?>
            <li class="page-item">
                <a class="page-link" href="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first'?>">
                    <span aria-hidden="true"><?= lang('Pager.first'?></span>
                </a>
            </li>
            <li class="page-item">
                <a class="page-link" href="<?= $pager->getPreviousPage() ?>" aria-label="<?= lang('Pager.previous'?>">
                    <span aria-hidden="true"><?= lang('Pager.previous'?></span>
                </a>
            </li>
        <?php endif ?>

        <?php foreach ($pager->links() as $link) : ?>
            <li <?= $link['active']  'class="page-item active"' '' ?>>
                <a class="page-link" href="<?= $link['uri'?>">
                    <?= $link['title'?>
                </a>
            </li>
        <?php endforeach ?>

        <?php if ($pager->hasNextPage()) : ?>
            <li class="page-item">
                <a class="page-link" href="<?= $pager->getNextPage() ?>" aria-label="<?= lang('Pager.next'?>">
                    <span aria-hidden="true"><?= lang('Pager.next'?></span>
                </a>
            </li>
            <li class="page-item">
                <a class="page-link" href="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last'?>">
                    <span aria-hidden="true"><?= lang('Pager.last'?></span>
                </a>
            </li>
        <?php endif ?>
    </ul>
</nav>


---------------------------------------------------

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

---------------------------------------------------

<?php
/**
 * app\Views\Pagination.php
 * 
 * I use this in latouts, so do what you need.
 * 
 * @var TYPE_NAME $currentPage
 * @var TYPE_NAME $totalPages
 */
?>

<!-- Pagination -->
<div class="pagination justify-content-center my-4">
    <?php if ( ! empty($pager)) :
        //echo $pager->simpleLinks('group1', 'bs_simple');
        echo $pager->links('group1''bs_full');
    endif ?>

    <!-- Bootstrap 5.3.1 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;
        // $currentPage and $totalPages are passed in through $data.
        <button type="button" class="btn btn-light"><?= 'Page ' $currentPage ' of ' $totalPages?></button>
    </div>
</div>

----------------------------------------- 
What did you Try? What did you Get? What did you Expect?

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

We understand that. Fine. Try in bs_simple.php output the total number and the current page. Hm?
Reply
#7

Well if you follow my code you will see that it does work.
What did you Try? What did you Get? What did you Expect?

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

I'll repeat it too: You pass values through the controller, but the render does not contain them
PHP Code:
// Add to your Controller.

$data = [
    'pager'      => $posts->pager,
    'currentPage' => $posts->pager->getCurrentPage('group1'),
    'totalPages'  => $posts->pager->getPageCount('group1'),
]; 
Reply
#9

If you open up system\Pager you will see what it does.

PHP Code:
public function getTotal(string $group 'default'): int

public function getPageCount(string $group 'default'): int

public function getCurrentPage(string $group 'default'): int

public function getPerPage(string $group 'default'): int

  
/**
    * Returns an array with details about the results, including
    * total, per_page, current_page, last_page, next_url, prev_url, from, to.
    * Does not include the actual data. This data is suitable for adding
    * a 'data' object to with the result set and converting to JSON.
    */
    public function getDetails(string $group 'default'): array 
What did you Try? What did you Get? What did you Expect?

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

No, no, no. Read post. I know how to work with Pager myself. The issue affects CodeIgniter\Pager\PagerRenderer
PHP Code:
<?php
/**
* app\Views\Pager\bs_simple.php - Bootstrap 5.3.1 Pager Template.
* @var \CodeIgniter\Pager\PagerRenderer $pager
*/

$pager->setSurroundCount(0);

/** Get $pager->getTotal() here. Not Pager! */
?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB