/VisualPaginator

Visual Paginator for Nette Framework.

Primary LanguagePHPMIT LicenseMIT

Visual Paginator

Visual Paginator for Nette Framework.

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

$ composer require aleswita/visualpaginator:dev-master

Usage

Presenter

use AlesWita\Components\VisualPaginator;


final class HomePresenter extends BasePresenter
{
	...
	...

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

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

	/**
	 * @return AlesWita\Components\VisualPaginator
	 */
	protected function createComponentPaginator(): AlesWita\Components\VisualPaginato {
		$vp = new VisualPaginator;
		// paginator have 3 predefined templates: TEMPLATE_NORMAL, TEMPLATE_BOOTSTRAP_V3 and TEMPLATE_BOOTSTRAP_V4	
		$vp->setPaginatorTemplate(VisualPaginator::TEMPLATE_BOOTSTRAP_V3);
		
		return $vp;
	}
}

Template

{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:

$vp->setCanSetItemsPerPage(TRUE);

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

$vp->setItemsPerPageList([10 => "10", 15 => "15"]);

Session

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

$vp->setSession($this->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");

Ajax

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

$vp->setAjax(TRUE);

And set onPaginate[] callback for redraw your snippets:

$vp->onPaginate[] = function(){
	if ($this->isAjax()) {
		$this->redrawControl("snippet");
	}
};

Translations

Paginator have accepted Nette\Localization\ITranslator for translators:

$vp->setTranslator($this->translator);

For changing the pre-defined texts:

$vp->setText("send", "paginator.send")
	->setText("itemsPerPage", "paginator.itemsPerPage");