VisualPaginator for Nette Framework.

3.0 2017-06-01 11:05 UTC


Visual Paginator for Nette Framework.

Build Status Coverage Status


The best way to install AlesWita/VisualPaginator is using Composer:

# For PHP 7.1 and Nette Framework 2.4/3.0
$ composer require aleswita/visualpaginator:dev-master

# For PHP 7.0/7.1 and Nette Framework 2.3/2.4
$ composer require aleswita/visualpaginator:2.0

# For PHP 5.6 and Nette Framework 2.3
$ composer require aleswita/visualpaginator:1.0



use AlesWita\Components\VisualPaginator;

final class HomePresenter extends BasePresenter

	public function renderDefault(): void {
		$dataSource = $this->model->getDataSource();
		$dataSource->applyLimit($this["paginator"]->getItemsPerPage(), $this["paginator"]->getOffset());

		$this->template->items = $dataSource;

	 * @return VisualPaginator
	protected function createComponentPaginator(): VisualPaginator {
		$vp = new VisualPaginator;
		// paginator have 3 predefined templates: TEMPLATE_NORMAL, TEMPLATE_BOOTSTRAP_V3 and TEMPLATE_BOOTSTRAP_V4
		$vp::$paginatorTemplate = VisualPaginator::TEMPLATE_BOOTSTRAP_V3;

		return $vp;


{control paginator}

More options

Items per page

Visitors can select from list, how many items shows. Predefined values for choice are 10, 20, 30, 40, 50 and 100:


You can set your choices (remember, keys in array must be numeric):

$vp::$itemsPerPageList = [10 => "10", 15 => "15"];


If you set Nette\Http\Session object, paginator save the value from items per page form to session:


If you have more than one paginators on your page, items per page saved separated by module / presenter / action. For all paginator saved to one property, use second parameter in setSession method:

$vp->setSession($this->session, "paginator");

Session namespace for paginator in default is "Visual-Paginator", for change you can use third parameter in setSession method:

$vp->setSession($this->session, "paginator", "my-namespace");


If you are like using ajax for paginate, don't worry and enabled ajax to true:


And set onPaginate[] callback for redraw your snippets:

$vp->onPaginate[] = function(): void {
	if ($this->isAjax()) {


Paginator have accepted Nette\Localization\ITranslator for translators:


For changing the pre-defined texts:

$vp::$messages["send"] = "paginator.send";
$vp::$messages["itemsPerPage"] = "paginator.itemsPerPage";

Configuration by DI

Setup in config.neon:

	visualpaginator: AlesWita\Components\VisualPaginatorExtension

	session: @Nette\Http\Session
	translator: @Nette\Localization\ITranslator
	template: AlesWita\Components\VisualPaginator::TEMPLATE_BOOTSTRAP_V4 # without '@' !!!
	itemsPerPageList: [1: 1, 2: 2, 3: 3]
		"send": "paginator.send"
		"itemsPerPage": "paginator.itemsPerPage"

And usage in presenter:

use AlesWita\Components\VisualPaginator;

final class HomePresenter extends BasePresenter
	/** @var AlesWita\Components\VisualPaginator @inject */
	public $visualPaginator;


	 * @return AlesWita\Components\VisualPaginator
	protected function createComponentPaginator(): AlesWita\Components\VisualPaginator {
		$vp = $this->visualPaginator;


		return $vp;