Category Archives: Adminhtml Grids

○ Create a simple form and grid for a custom entity
○ Describe how to implement advanced Adminhtml Grids and Forms, including editable cells, mass actions, totals, reports, custom filters and renderers, multiple grids on one page, combining grids with forms, and adding custom JavaScript to an admin form:
■ Which block class do Magento grid classes typically extend?
■ What is the default template for Magento grid instances?
■ How can grid filters be customized?
■ How does Magento actually perform sorting/paging/filtering operations?
■ What protected methods are specific to adminhtml grids, and how are they used?
■ What is the standard column class in a grid, and what is its role?
■ What are column renderers used for in Magento?
■ How can JavaScript that is used for a Magento grid be customized?
■ What is the role of the grid container class and its template?
■ What is the programmatic structure of mass actions?
These code references can be used as an entry point to find answers to the questions above:
■ Mage_Adminhtml_Block_Widget_Grid
■ Mage_Adminhtml_Block_Widget_Grid_Column
■ Mage_Adminhtml_Block_Widget_Grid_Column_Renderer/*
■ Mage_Adminhtml_Block_Widget_Grid_Column_Filter/*
■ Mage_Adminhtml_Block_Widget_Grid_Container
■ app/design/adminhtml/default/default/template/wid get/grid.phtml
■ app/design/adminhtml/default/default/template/wid
get/grid/container.phtml

Adding A Custom Column To The Adminhtml Grid Widget

Recently it was necessary to add a new custom column to the Adminhtml Grid widget, as a new delivery date value had been created but was not appearing in the orders view associated to the customer.

So the form to be modified has been centralised and can be found at: /app/design/adminhtml/default/{theme}/template/widget/grid.phtml

at the top of this form the following was added, based on the requirement of the custom delivery date field that had already been created.

$this->addColumn('delivery_datetime', array(
    'header' => $this->__('Delivery Datetime'),
    'index' => 'delivery_datetime',
    'type' => 'date',
    'width' => '100px',
));

This was superb and added the column to the end of the grid. However, it was far more useful to apply the column after the store information, so the order of the grid was changed with the following code snippet:

$this->addColumnsOrder('delivery_datetime', 'store_id')
    ->sortColumnsByOrder();

The store_id value was extracted when the following debug code was added into the form, which while a little unsightly, both from a coding and a layout perspective, identified the values involved in the grid:

‘);
var_dump ($innerInnerColumn);
}
}
}
?>
[\php]

This code was placed after

<?php foreach ($this->getColumns() as $_column): ?>

Resources:
magento-grid-column-position

Redirect In Grid To Admin URL

As part of the creation of a grid that contained sales orders, it was necessary to redirect the click on a grid row to the sales order view for the id of the row in question.

To accomplish this the following code was used in the Grid.php file:

public function getRowUrl($row) {
    return ($this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getId())));
}

Note that the adminhtml in the return line above was replaced with the magic key string for the administrator area.