I am using following code to filter result and i want to limit the result.
$giftColletion = $this->_giftFactory->getCollection();
$giftColletion->addFieldToFilter('store_id', 1);
$giftColletion->setOrder('position','ASC');
I am using following code to filter result and i want to limit the result.
$giftColletion = $this->_giftFactory->getCollection();
$giftColletion->addFieldToFilter('store_id', 1);
$giftColletion->setOrder('position','ASC');
You can use setPageSize() to use limit in collection
$giftColletion = $this->_giftFactory->getCollection();
$giftColletion->addFieldToFilter('store_id', 1);
$giftColletion->setOrder('position','ASC');
$giftColletion->setOrder('salary','ASC');
$giftColletion->setPageSize(10);
Using Page size you can set limit:
$giftColletion = $this->_giftFactory->getCollection();
$giftColletion->addFieldToFilter('store_id', 1);
$giftColletion->setOrder('position','ASC');
$giftColletion->setPageSize($pageSize);
$giftColletion->setCurPage($page);
$giftColletion = $this->_giftFactory->getCollection()->addFieldToFilter('store_id', 1);
$giftColletion->setOrder('position', 'ASC');
$giftColletion->setOrder('attribute_code', 'ASC');
$giftColletion->setPageSize($limitNo);
I normally use the following but setPageSize()
is also valid:
$collection->getSelect()->limit($limit);
Regarding sorting, if the direction of your sorting is the same for all fields, you can set that in just one call using an array:
$collection->setOrder([$field1, $field2, ...], $dir);
Order by :
$giftColletion->setOrder('position','ASC');
$giftColletion->setOrder('store_id','ASC');
You can use below code.
$giftColletion = $this->_giftFactory->getCollection();
$giftColletion->addFieldToFilter('store_id', 1)->setPageSize($limit)->setCurPage($criteria)->setOrder('position','ASC');