0

I am using magento2 pagination on custom collection it is working fine but, Pagination Frame, Pagination Frame Skip, not working on custom collection

Setting Pagination Settings from Content > Design > Configurations > Pagination

enter image description here

But it is not working on frontend on custom collection

enter image description here

It should be 1 2 ...

1 Answer 1

0

The config settings for pagination are applied only to the product list and the wishlist items. If you want to use the same restrictions in your own pagination you need to set them manually.

I assume you have somewhere in a class an instance of the page block \Magento\Theme\Block\Html\Pager. Let's call the instance $pager.
I alsi assume you do something like this $pager->setCollection(...).

You can apply the "frame" and "skip" limitations like this

$pager->setFrameLenght(2);
$pager->setJump(2);

If you want to use the same values as listed in config you need to do this

$pager->setFrameLength(
    $this->scopeConfig->getValue(
        'design/pagination/pagination_frame',
        \Magento\Store\Model\ScopeInterface::SCOPE_STORE
    )
);
$pager->setJump(
    $this->scopeConfig->getValue(
        'design/pagination/pagination_frame_skip',
        \Magento\Store\Model\ScopeInterface::SCOPE_STORE
    )
);

where $this->scopeConfig is an instance of \Magento\Framework\App\Config\ScopeConfigInterface that you can add as dependency to your class that uses the pager.

/** @var `Magento\Framework\App\Config\ScopeConfigInterface */
private $scopeConfig; 

public function __construct(
    ...
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
    ....
    $this->scopeConfig = $scopeConfig;
}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.