Componette

Componette

ipublikuj-archive

ipublikuj-archive / visual-paginator v2.0.1

Visual paginator for Nette Framework

download-cloud-line composer require ipub/visual-paginator

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;
	}
}
  • v2.0.1 v2.0.1

    • Just renaming organization
  • v2.0.0 v2.0.0

  • v1.0.7 v1.0.7

  • v1.0.6 v1.0.6

    • Fixed: Undefined variable: templateFile
  • v1.0.5 v1.0.5

    • Fixing empty links
  • v1.0.4 v1.0.4

    • Fixed naming
  • v1.0.3 v1.0.3

    • Added Foundation template
    • Small fixes in bootstrap template
  • v1.0.2 v1.0.2

    • Minor updates
  • v1.0.1 v1.0.1

    • Updated templates handling
  • v1.0.0 v1.0.0

    First stable release Nette visual component

Componette Componette felix@nette.org