I added a custom column to display weight of the product in product grid.
The grid displays the weights correctly, when filtered, the column disappears, but if refresh the page it returns and filters the records, when ordering the same thing happens.
I do not know why that happens, do not want to override the default magento code, just add a column without involving alerar codes pattern.
My codes:
config.xml
<adminhtml>
events>
<eav_collection_abstract_load_before>
<observers>
<dexxtz_customgrid>
<class>dexxtz_customgrid/observer</class>
<method>onEavLoadBefore</method>
</dexxtz_customgrid>
</observers>
</eav_collection_abstract_load_before>
</events>
</adminhtml>
layout.xml
<layout>
<catalog_product_grid_update_handle translate="label" module="dexxtz_customgrid">
<reference name="product.grid">
<action method="addColumnAfter" ifconfig="dexxtz_customgrid/weight/active">
<columnId>weigth</columnId>
<arguments helper="customgrid/getWeightColumnParams" />
</action>
</reference>
</catalog_product_grid_update_handle>
<adminhtml_catalog_product_grid>
<update handle="catalog_product_grid_update_handle" />
</adminhtml_catalog_product_grid>
<adminhtml_catalog_product_index>
<update handle="catalog_product_grid_update_handle" />
</adminhtml_catalog_product_index>
</layout>
Observer.php
<?php
class Dexxtz_Customgrid_Model_Observer
{
public function onEavLoadBefore(Varien_Event_Observer $observer) {
$collection = $observer->getCollection();
if (!isset($collection)) return;
if (is_a($collection, 'Mage_Catalog_Model_Resource_Product_Collection')) {
$collection->addAttributeToSelect('weight');
}
}
}
function getWeightColumnParams()
public function getWeightColumnParams()
{
$array = array('header' => 'Weight',
'index' => 'weight',
'filter_index' => 'weight',
'header_css_class' => 'a-center',
'align' => 'center',
'type' => 'text',
'width' => 100);
return $array;
}
The problem seems to be in:
<adminhtml_catalog_product_grid>
<update handle="catalog_product_grid_update_handle" />
</adminhtml_catalog_product_grid>
http://www.magentocommerce.com/boards/viewthr./viewthread/268277/
updated the catalog.xml and did not work