Filter Not Working in Grid – Troubleshooting Guide

backendgridgrid-serlization

I have a custom module with a backend grid and an edit form.
In the edit form I have some tab one contains a grid for associated products.

I have implemented the grid int the tab using the code from the products grid for related products.

Now everything seems to work and checkbox are selected according to data from collection.

The only issue is related to the filter Yes/No/Any that doesn't work:
setting the filter to "yes" I have an empty grid, instead if I set the filter to "No/Any" I can see all the products and also the product selected.

So it looks like some association to between the filter and the field name are missed

Best Answer

On the webguys page is a german article about this problem: http://www.webguys.de/magento/turchen-23-pimp-my-produktgrid/

Nicht alle unsere Änderungen werden von Magento übernommen, zum Beispiel funktioniert die Sortierung und Filterung der neuen Attribute nicht.

Das liegt daran, dass unsere Änderungen nach dem Aufruf von _prepareCollection(), in dem die Spalteninfos an die Collection übergeben werden, stattfinden.

Translation:

Not all changes are made by magento, e.g. sorting and filtering of the new attributes doesn't work.

That's because they are made after the _prepareCollection() call, where the informations about the columns are passed to the collection.

protected function _callProtectedMethod($object, $methodName) {
    $reflection = new ReflectionClass($object);
    $method = $reflection->getMethod($methodName);
    $method->setAccessible(true);
    return $method->invoke($object);
}

protected function _modifyProductGrid(Mage_Adminhtml_Block_Catalog_Product_Grid $grid) {
 
    $this->_addUpdatedAtColumn($grid);
    $this->_addColorColumn($grid);
 
    $this->_removeColumn($grid, 'set_name');
    $this->_removeColumn($grid, 'visibility');       

    // reinitialisiert die Spaltensortierung
    $grid->sortColumnsByOrder();
    // reinitialisiert die Sortierung und Filter der Collection
    $this->_callProtectedMethod($grid, '_prepareCollection');               

} 

More in the post. I think the source code is quite self explaining and if not, use google (if you don't understand german ;-))

Related Topic