Skip to content

spernica/visual-paginator

 
 

Repository files navigation

Visual Paginator

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;
	}
}

About

Visual paginator for Nette Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 78.1%
  • Latte 13.5%
  • CSS 8.0%
  • HTML 0.4%