Magento

Magento custom collection filter and sort

Magento custom collection filter and sort

Magento custom collection filter and sort

 

We have already know how to filter magento product ,customer,wishlist,order  collection  fields filters.

But whenever we are working on  non-exiting model collection, then we facing problem.Here i have put some tricks how you can filter a custom collection by a field.In post,i have working on a writing how a custom collection is filter by a filed and how the collection will filter.

Suppose a custom collection is

For add addFieldToSelect('*') at that Collection for retrieves all field value for a module is

Then want to filter that collection by a field name ‘age’ then use

For add for sort by a specific field then add setOrder('fieldname','SortOrder');
Example want to sort by age descending then try this

for fetch limit number of rows of a collection use setPageSize(number_of_rows)

Leave a Reply

Your email address will not be published. Required fields are marked *