Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Pagination summary
  • 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.
  • 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.
  • 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?


  • I pondered your earlier statement and achieved what I wanted with the code below.

    ------------------
    <?php
        $stpl = "Showing &emsp;%s&emsp; to &emsp;%s&emsp; of &emsp;%s&emsp; 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.
  • HarroHarro
    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
  • Our posts crossed... ;)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion