Skip to content
Items per page control for Nette Framework
PHP HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpstan.neon

README.md

Items per page


Build Status Licence Latest stable PHPStan

Installation

The recommended way to is via Composer:

composer require surda/items-per-page

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

extensions:
    itemsPerPage: Surda\ItemsPerPage\ItemsPerPageExtension

Configuration

Default

itemsPerPage:
    listOfValues: [20, 50, 100]
    defaultValue: 20
    storageKeyName: ipp
    useAjax: TRUE
    storage: Surda\KeyValueStorage\Session
    templates:
        default: bootstrap4.dropdown.latte
        nav-item: bootstrap4.nav-item.latte

Usage

Presenter

use Surda\ItemsPerPage\TItemsPerPage;
use Surda\ItemsPerPage\ItemsPerPageControl;

class ProductPresenter extends Nette\Application\UI\Presenter
{
    use TItemsPerPage;

    public function actionDefault(): void
    {
        /** @var ItemsPerPageControl $ipp */
        $ipp = $this->getComponent('ipp');

        $itemsPerPage = $ipp->getValue();
    }
}

Template

{control ipp}

Custom

use Surda\ItemsPerPage\ItemsPerPageControl;
use Surda\ItemsPerPage\ItemsPerPageFactory;

class ProductPresenter extends Nette\Application\UI\Presenter
{
    /** @var ItemsPerPageFactory */
    private $itemsPerPageFactory;

    /**
     * @param ItemsPerPageFactory $itemsPerPageFactory
     */
    public function injectItemsPerPageFactory(ItemsPerPageFactory $itemsPerPageFactory): void
    {
        $this->itemsPerPageFactory = $itemsPerPageFactory;
    }

    public function actionDefault(): void
    {
        /** @var ItemsPerPageControl $ipp */
        $ipp = $this->getComponent('ipp');

        $itemsPerPage = $ipp->getValue();
    }

    /**
     * @return ItemsPerPageControl
     */
    protected function createComponentIpp(): ItemsPerPageControl
    {
        // Init items per page component
        $control = $this->itemsPerPageFactory->create();
        
        // Define event
        $control->onChange[] = function (ItemsPerPageControl $control, int $value): void {
            // ...
        };

        return $control;
    }
}

Custom options

class ProductPresenter extends Nette\Application\UI\Presenter
{
    /**
     * @return ItemsPerPageControl
     */
    protected function createComponentIpp(): ItemsPerPageControl
    {
        // Init items per page component
        $control = $this->itemsPerPageFactory->create();
        
        // list of allowed values 
        $control->setListOfValues([20, 50, 100]);

        // Default items per page
        $control->setDefaultValue(20);

        // Value of items per page
        $control->setValue(20);

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

        // Enable ajax (defult is enabled)
        $control->enableAjax();
        
        // Disable ajax
        $control->disableAjax();
        
        return $control;
    }
}
You can’t perform that action at this time.