Magento, on administration side, has the concept of “grid”, a table with ability to filter, order, page a collection of data. For example the product list is a grid.

A grid is usually initialized on block implementation that “prepares columns” and when I needed to change the columns of a grid I overloaded the block implementation with a class of mine extending the original one.

The latest modification I made on Magento was on product list tab present on category detail. I found incredibly stupid in Magento the absence of a category filter on product management panel and an edit action on product list on category detail.

Since the simpler thing was to add an action to that table I overrided the

Adminhtml/Block/Catalog/Category/Tab/Product.php

block implementation, which is a Magento grid. The only thing needed was to add a “modify” action, opening in a new window.

So I added a column (on my class, without modify the original one):

$this->addColumn('action',
    array(
    'header'    => Mage::helper('catalog')->__('Action'),
    'width'     => '50px',
    'type'      => 'action',
    'getter'     => 'getId',
    'actions'   => array(
        array(
        'caption' => 'Edit',
        'url'     => array(
            'base'=>'*/catalog_product/edit'
        ),
        'target'=>'_blank',
        'field'   => 'id'
        )
    ),
    'filter'    => false,
    'sortable'  => false
));

But that action, apart the check box triggering on click which seems hard to remove, was not opening on a new window. Searching how the action is rendered I discovered the class

Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action

which implements a number of action, from standard link to selects. That class uses the “actions” array you can see in previous code capturing every thing is not part of the URL building process and uses it as A tag attribute. So, to make the action open on a new tab only the addition of a “target” parameter was required.

Simple to do, hard to find… and may be somewhere that is documented but I was not able to discover where!

Yes this post is missing images, I’ll complete it with screenshots asap.

 

 

Similar Posts

2 Comments

Leave a Reply