Magento 2 Collection Set Page Size Limit


Magento 2 Collection Set Page Size Limit It is very simple to merge to collections in magento 2. Here in this tutorial we are going to explain how to set page size in collection.


Magento 2 Collection Set Page Size Limit | Curpage Example

You can set the page size of collection in magento simply as below-

Set Page Size

->setPageSize($pageSize); is used to set the current collection size in magento 2. Here is an example-

Magento 2 Collection Set Page Size Limit Example:

public function getMyData(){
        $pageSize= 10;
        $newCollection = $this->newcollectionFactory->create();
        $newCollection->setPageSize($pageSize);
        return $newCollection;
}

Set Current Page

If you are using pagination then you can use ->setCurPage($page); is used to set the current page in magento 2. Here is an example-

Magento 2 Collection Set Cur Page Example:

public function getMyData(){
       
         $page=($this->getRequest()->getParam('p'))? $this->getRequest()->getParam('p') : 1;
   
        $newCollection = $this->newcollectionFactory->create();
        $newCollection->setCurPage($page);
        return $newCollection;
}

Where $page is current page.


Advertisements

Add Comment

📖 Read More