API16

Difference between revisions of "JPagination"

From Joomla! Documentation

Line 58: Line 58:
 
===Examples===
 
===Examples===
 
<CodeExamplesForm />
 
<CodeExamplesForm />
 +
<dpl>
 +
noresultsheader=\n
 +
category=JPagination
 +
category=CodeExample
 +
category=ClassExample
 +
include=*
 +
format= ,,,
 +
</dpl>

Revision as of 11:42, 28 September 2010

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

[Edit Descripton] Template:Description:JPagination

Defined in[edit]

libraries/joomla/html/pagination.php

Methods[edit]

Method name Description
__construct Constructor.
setAdditionalUrlParam Method to set an additional URL parameter to be added to all pagination class generated links.
getAdditionalUrlParam Method to get an additional URL parameter to be added to all pagination class generated links if it exists.
getRowOffset Return the rationalised offset for a row with a given index.
getData Return the pagination data object, only creating it if it doesn't already exist.
getPagesCounter Create and return the pagination pages counter string, ie. Page 2 of 4.
getResultsCounter Create and return the pagination result set counter string, ie. Results 1-10 of 42
getPagesLinks Create and return the pagination page list string, ie. Previous, Next, 1 2 3 ... x.
getListFooter Return the pagination footer.
getLimitBox Creates a dropdown box for selecting how many records to show per page.
orderUpIcon Return the icon to move an item UP.
orderDownIcon Return the icon to move an item DOWN.

Importing[edit]

jimport( 'joomla.html.pagination' );

[Edit See Also] Template:SeeAlso:JPagination

Examples[edit]

<CodeExamplesForm />

JPagination on Frontpage

Mariska wrote:

if you want to Jpagination work on front page change Jpagination.php

on this code function _buildDataObject bicause this method use to generate link on front end // add "&limit=".$this->limit to $data->[]->link

   function _buildDataObject() {
       // Initialize variables
       $data = new stdClass();
       $data->all = new JPaginationObject(JText::_('View All'));
       if (!$this->_viewall) {
           $data->all->base = '0';
           $data->all->link = JRoute::_("&limit=".$this->limit."&limitstart="); // <== this  
       }
       // Set the start and previous data objects
       $data->start = new JPaginationObject(JText::_('Start'));
       $data->previous = new JPaginationObject(JText::_('Prev'));
       if ($this->get('pages.current') > 1) {
           $page = ($this->get('pages.current') - 2) * $this->limit;
          $page = $page == 0 ?  : $page; //set the empty for removal from route
           $data->start->base = '0';
           $data->start->link = JRoute::_("&limit=".$this->limit."&limitstart="); //<== this
           $data->previous->base = $page;
           $data->previous->link = JRoute::_("&limit=".$this->limit."&limitstart=" . $page); //<== this
       }
       // Set the next and end data objects
       $data->next = new JPaginationObject(JText::_('Next'));
       $data->end = new JPaginationObject(JText::_('End'));
       if ($this->get('pages.current') < $this->get('pages.total')) {
           $next = $this->get('pages.current') * $this->limit;
           $end = ($this->get('pages.total') - 1) * $this->limit;
           $data->next->base = $next;
           $data->next->link = JRoute::_("&limit=".$this->limit."&limitstart=" . $next); // <== this
           $data->end->base = $end;
           $data->end->link = JRoute::_("&limit=".$this->limit."&limitstart=" . $end); // <== this
       }
       $data->pages = array();
       $stop = $this->get('pages.stop');
       for ($i = $this->get('pages.start'); $i <= $stop; $i++) {
           $offset = ($i - 1) * $this->limit
           $offset = $offset == 0 ?  : $offset;  //set the empty for removal from route
           $data->pages[$i] = new JPaginationObject($i);
           if ($i != $this->get('pages.current') || $this->_viewall) {
               $data->pages[$i]->base = $offset;
               $data->pages[$i]->link = JRoute::_("&limit=".$this->limit."&limitstart=" . $offset); //<== this
           }
       }
       return $data;
   }

Batch1211 05:42, 27 September 2010 (CDT) Edit comment

Pagination like Google

Stop hand nuvola.svg.png
Warning!

This is a core hack. Files you change as described on this page will be overwritten during updates of Joomla!. For more information, see Core hack.

  • edit the libraries/joomla/html/pagination.php
  • In the function __construct see the line $displayedPages = 10;
  • Replace the $this->set( 'pages.start',... with the following lines
  $_remainder = $this->get('pages.current') % $displayedPages;
  if($__remainder == 0){
     $this->set( 'pages.start', (floor( $this->get('pages.current') / $displayedPages)) * $displayedPages -4);  
  }elseif($__remainder == 1 and $this->get('pages.current') > $displayedPages){
     $this->set( 'pages.start', (floor( ($this->get('pages.current')-1) / $displayedPages)) * $displayedPages -4);  
  }else{
    $this->set( 'pages.start', (floor( $this->get('pages.current') / $displayedPages)) * $displayedPages + 1);
  }
  • In the function _buildDataObject find the line
 for ($i = $this->get('pages.start'); $i <= $stop; $i ++)
  • In this for loop, find the line
 if ($i != $this->get('pages.current') || $this->_viewall)
  • Add the elseif statement,
 if ($i != $this->get('pages.current') || $this->_viewall)
 {
   $data->pages[$i]->base = $offset;
   $data->pages[$i]->link = JRoute::_("&limitstart=".$offset);
 }elseif($i == $this->get('pages.current')){
   $data->pages[$i]->text = '<b>' . $i . '</b>';
 }

This example was originally contributed by User:Mahboobkhalid.


Chris Davenport 13:38, 17 April 2011 (CDT) Edit comment

[

Edit Descripton] The JPagination class supports pagination of lists of items across multiple pages. It can be used in both the front-end and back-end, although there are slight differences in behaviour. The HTML output can be overridden using a template layout override.

Defined in[edit]

libraries/joomla/html/pagination.php

Methods[edit]

Method name Description
__construct Constructor
getRowOffset Return the rationalised offset for a row with a given index.
getData Return the pagination data object, only creating it if it doesn't already exist
getPagesCounter Create and return the pagination pages counter string, ie. Page 2 of 4
getResultsCounter Create and return the pagination result set counter string, ie. Results 1-10 of 42
getPagesLinks Create and return the pagination page list string, ie. Previous, Next, 1 2 3 ... x
getListFooter Return the pagination footer
getLimitBox Creates a dropdown box for selecting how many records to show per page
orderUpIcon Return the icon to move an item UP
orderDownIcon Return the icon to move an item DOWN

Importing[edit]

jimport( 'joomla.html.pagination' );


See also[edit]

Examples[edit]

Code Examples[edit]

´

JPagination on Frontpage

Mariska wrote:

if you want to Jpagination work on front page change Jpagination.php

on this code function _buildDataObject bicause this method use to generate link on front end // add "&limit=".$this->limit to $data->[]->link

   function _buildDataObject() {
       // Initialize variables
       $data = new stdClass();
       $data->all = new JPaginationObject(JText::_('View All'));
       if (!$this->_viewall) {
           $data->all->base = '0';
           $data->all->link = JRoute::_("&limit=".$this->limit."&limitstart="); // <== this  
       }
       // Set the start and previous data objects
       $data->start = new JPaginationObject(JText::_('Start'));
       $data->previous = new JPaginationObject(JText::_('Prev'));
       if ($this->get('pages.current') > 1) {
           $page = ($this->get('pages.current') - 2) * $this->limit;
          $page = $page == 0 ?  : $page; //set the empty for removal from route
           $data->start->base = '0';
           $data->start->link = JRoute::_("&limit=".$this->limit."&limitstart="); //<== this
           $data->previous->base = $page;
           $data->previous->link = JRoute::_("&limit=".$this->limit."&limitstart=" . $page); //<== this
       }
       // Set the next and end data objects
       $data->next = new JPaginationObject(JText::_('Next'));
       $data->end = new JPaginationObject(JText::_('End'));
       if ($this->get('pages.current') < $this->get('pages.total')) {
           $next = $this->get('pages.current') * $this->limit;
           $end = ($this->get('pages.total') - 1) * $this->limit;
           $data->next->base = $next;
           $data->next->link = JRoute::_("&limit=".$this->limit."&limitstart=" . $next); // <== this
           $data->end->base = $end;
           $data->end->link = JRoute::_("&limit=".$this->limit."&limitstart=" . $end); // <== this
       }
       $data->pages = array();
       $stop = $this->get('pages.stop');
       for ($i = $this->get('pages.start'); $i <= $stop; $i++) {
           $offset = ($i - 1) * $this->limit
           $offset = $offset == 0 ?  : $offset;  //set the empty for removal from route
           $data->pages[$i] = new JPaginationObject($i);
           if ($i != $this->get('pages.current') || $this->_viewall) {
               $data->pages[$i]->base = $offset;
               $data->pages[$i]->link = JRoute::_("&limit=".$this->limit."&limitstart=" . $offset); //<== this
           }
       }
       return $data;
   }

Batch1211 05:42, 27 September 2010 (CDT) Edit comment

Pagination like Google

Stop hand nuvola.svg.png
Warning!

This is a core hack. Files you change as described on this page will be overwritten during updates of Joomla!. For more information, see Core hack.

  • edit the libraries/joomla/html/pagination.php
  • In the function __construct see the line $displayedPages = 10;
  • Replace the $this->set( 'pages.start',... with the following lines
  $_remainder = $this->get('pages.current') % $displayedPages;
  if($__remainder == 0){
     $this->set( 'pages.start', (floor( $this->get('pages.current') / $displayedPages)) * $displayedPages -4);  
  }elseif($__remainder == 1 and $this->get('pages.current') > $displayedPages){
     $this->set( 'pages.start', (floor( ($this->get('pages.current')-1) / $displayedPages)) * $displayedPages -4);  
  }else{
    $this->set( 'pages.start', (floor( $this->get('pages.current') / $displayedPages)) * $displayedPages + 1);
  }
  • In the function _buildDataObject find the line
 for ($i = $this->get('pages.start'); $i <= $stop; $i ++)
  • In this for loop, find the line
 if ($i != $this->get('pages.current') || $this->_viewall)
  • Add the elseif statement,
 if ($i != $this->get('pages.current') || $this->_viewall)
 {
   $data->pages[$i]->base = $offset;
   $data->pages[$i]->link = JRoute::_("&limitstart=".$offset);
 }elseif($i == $this->get('pages.current')){
   $data->pages[$i]->text = '<b>' . $i . '</b>';
 }

This example was originally contributed by User:Mahboobkhalid.


Chris Davenport 13:38, 17 April 2011 (CDT) Edit comment