How do add additional column in admin grid ?

, , No Comments

To add additional column to your grid, you need to open your grid block from required module. Let me explain with custom module to add additional column.

My custom module Structure

  • Custom
  • -Sample
  • --Block
  • ---Adminhtml
  • ----Sample
  • -----Grid.php

We need to work on the Grid.php file.This file contains different type of functions to display content in the grid.We need to search _prepareColumns() functions and work on that..

I already contain some columns to display informations.First I will show one from this grid.

$this->addColumn('title', array(
'header' => Mage::helper('sample')->__('Title'),
'align' =>'left',
'index' => 'title',
));

addColumn function create one column with 'Title' title in grid.The following details give the used variable's information.

  • 'title' => column name
  • 'header'=> Column Title
  • 'align' => Alignment of the this cloumn text
  • 'index' => Here i added 'title'.This is not static content. This is one cloumn value of this modal.We displayed title of the particular row's information,here we didplayed retireved information.

Now I like to show additional column.Here we display the description of this row.We already store description to this item.

Paste your existing column action and paste next to the existing column and edit column name to 'description'

$this->addColumn('description', array(
'header' => Mage::helper('sample')->__('Title'),
'align' =>'left',
'index' => 'title',
));

Edit the column title in the header variable in array

$this->addColumn('description', array(
'header' => Mage::helper('sample')->__('Description'),
'align' =>'left',
'index' => 'title',
));

Finally update index variable in array. We used 'item_description' to store the description of the item in table. Now we need to use this name 'item_description' in 'index' variable.

$this->addColumn('description', array(
'header' => Mage::helper('sample')->__('Description'),
'align' =>'left',
'index' => 'item_description',
));

After adding this description column, we can see new column with 'Description' Title in the admin grid.

Reference:

https://nikunjvadariya.wordpress.com/2013/06/13/magento-how-to-add-new-action-in-row-at-admin-grid-in-magneto/

0 comments:

Post a Comment