ipub/visual-paginator

This package is abandoned and no longer maintained. No replacement package was suggested.

Visual paginator for Nette Framework

v2.0.1 2019-05-24 18:33 UTC

This package is auto-updated.

Last update: 2020-02-14 11:16:25 UTC


README

Build Status Scrutinizer Code Quality Latest Stable Version Composer Downloads

Visual paginator for Nette Framework

Installation

The best way to install ipub/visual-paginator is using Composer:

{
	"require": {
		"ipub/visual-paginator": "dev-master"
	}
}

or

$ composer require ipub/visual-paginator:@dev

After that you have to register extension in config.neon.

extensions:
	visualPaginator: IPub\VisualPaginator\DI\VisualPaginatorExtension

Usage

Implementing into Presenter or Component

use IPub\VisualPaginator\Components as VisualPaginator;

class SomePresenter extends Nette\Application\UI\Presenter
{
	/**
	 * @var Model
	 */
	private $dataModel;

	public function renderDefault()
	{
		$someItemsList = $this->dataModel->findAll();

		// Get visual paginator components
		$visualPaginator = $this['visualPaginator'];
		// Get paginator form visual paginator
		$paginator = $visualPaginator->getPaginator();
		// Define items count per one page
		$paginator->itemsPerPage = 10;
		// Define total items in list
		$paginator->itemCount = $someItemsList->count();
		// Apply limits to list
		$someItemsList->limit($paginator->itemsPerPage, $paginator->offset);
	}

	/**
	 * Create items paginator
	 *
	 * @return VisualPaginator\Control
	 */
	protected function createComponentVisualPaginator()
	{
		// Init visual paginator
		$control = new VisualPaginator\Control;

		return $control;
	}
}

Enabling or disabling ajax support

This component bring ajax support. When ajax is enabled, then ajax class is inserted into links.

use IPub\VisualPaginator\Components as VisualPaginator;

class SomePresenter extends Nette\Application\UI\Presenter
{
	/**
	 * Create items paginator
	 *
	 * @return VisualPaginator\Control
	 */
	protected function createComponentVisualPaginator()
	{
		// Init visual paginator
		$control = new VisualPaginator\Control;

		// Enable ajax (by default)
		$control->enableAjax();

		// Or disable ajax
		$control->disableAjax();

		return $control;
	}
}

And now you have to define events what to do when next or previous page is loaded via Ajax request:

use IPub\VisualPaginator\Components as VisualPaginator;

class SomePresenter extends Nette\Application\UI\Presenter
{
	public function renderDefault()
	{
		$that = $this;

		//....

		// Define event for example to redraw snippets
		$this['visualPaginator']->onShowPage[] = (function ($component, $page) use ($that) {
			if ($that->isAjax()){
				$that->invalidateControl();
			}
		});
	}
}

Using templates

This component come with two default templates. One is basic default template, with some basic classes and the second one is Bootstrap FW template. And also you can use your own template:

use IPub\VisualPaginator\Components as VisualPaginator;

class SomePresenter extends Nette\Application\UI\Presenter
{
	/**
	 * Create items paginator
	 *
	 * @return VisualPaginator\Control
	 */
	protected function createComponentVisualPaginator()
	{
		// Init visual paginator
		$control = new VisualPaginator\Control;

		// To use bootstrap default template
		$control->setTemplateFile('bootstrap.latte');

		// To use your own template
		$control->setTemplateFile('path/to/your/latte/file.latte');

		return $control;
	}
}