Search This Blog

Wednesday 23 May 2012

Set Default filters for the Grid in Magento

To apply default filter for the grid view follow the instructions below:

Open your corresponding grid.php file and look for  the following
protected function _prepareCollection() {

Add the following line of code next to above code

$this->setDefaultFilter(array('featured'=>1));

 In above code ,  "featured" is the name of the field and 1 is the default value to be applied to filter. Also you can add any number of filter in the array with in setDefaultFilter function.




3 comments:

  1. Works perfect.If you need receive filter value from another module do in this way:

    // Example Filter by customer
    // 'customer' = the $_GET parameter
    // 'customer_id' the grid index value
    if ($customer = $this->getRequest()->getParam('customer'))
    $this->setDefaultFilter(array('customer_id' => $customer));

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
    magento development company in bangalore 

    ReplyDelete