Joomla 4.x Tutorial - Extension Development - Pagination

Modify this post

Quickly there is a lot of content. Displaying all elements on one page is not useful. It has a negative impact on the overview and performance. That's why we split the items on subpages and add pagination for navigation at the bottom.

Joomla Pagination

For impatient people

View the changed program code in the Diff Viewgithub.com/astridx/boilerplate/compare/t18...t19 and incorporate these changes into your development version.

Step by step

In the following overview, the newly added files are marked with a background and the changed ones are outlined.

Overview of the files edited in this chapter

New files

No new files are added.

Modified files

administrator/components/com_foos/ src/View/Foos/HtmlView.php

We do not have any special requests. To display the default pagination, more or less two lines are enough. In the view you call $this->pagination = $this->get('Pagination'); to set the variable $this->pagination.

administrator/components/com_foos/ src/View/Foos/HtmlView.php

 	protected $items;

	/**
	 * The pagination object
	 *
	 * @var  \JPagination
	 */
	protected $pagination;

 	/**
 	 * The model state
 	 *

 	public function display($tpl = null): void
 	{
 		$this->items = $this->get('Items');

		$this->pagination = $this->get('Pagination');
 		$this->filterForm = $this->get('FilterForm');
 		$this->activeFilters = $this->get('ActiveFilters');
 		$this->state = $this->get('State');

administrator/components/com_foos/ tmpl/foos/default.php

In the template we use the getListFooter method of the variable $this->pagination. That was all!

administrator/components/com_foos/ tmpl/foos/default.php

 						</tbody>
 					</table>

					<?php echo $this->pagination->getListFooter(); ?>

 				<?php endif; ?>
 				<input type="hidden" name="task" value="">
 				<input type="hidden" name="boxchecked" value="0">

In the global configuration you can set the number of elements that will be displayed by default. Normally this is set to 20 elements. Joomla Pagination in global configuration

Test your Joomla component

  1. install your component in Joomla version 4 to test it:

Copy the files in the administrator folder to the administrator folder of your Joomla 4 installation.

A new installation is not necessary. Continue using the ones from the previous part.

  1. open the view of your component in the administration area and create so many items that they are no longer displayed on one page. In the lower part you will see a navigation to browse through the contents.
Modify this post

Comments