Add extra column in admin sales order grid – magento

Add extra column in admin sales order grid – magento:
Custom column we can add it from admin -> sales -> order grid section. Add a new column is an simple one, follow below steps and and show your custom column in grid.

 Steps:

1. Override following function from below path file
app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php
protected function _prepareCollection() {}
protected function _prepareColumns(){}

2. Add your custom query after $collection = Mage::getResourceModel($this->_getCollectionClass()); this line
Ex Query :
Here am going to show “samplecolumn” column in a grid. Based on the requirement the query might be change. In this query am fetching
sales_flat_order_item query values.
$collection->getSelect()->joinLeft(array(‘sfi’ => ‘sales_flat_order_item’),
“main_table.entity_id = sfi.order_id” ,
array(“YOUR Condition”)));
$collection->getSelect()->group(array(‘main_table.entity_id’));

3. Now your customer column contain the values. You have to show in a grid
4. Add your custom column in _prepareColumns function, like below way

$this->addColumn(‘samplecolumn’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Sample Column’),
‘index’ => ‘samplecolumn’,
‘type’  => ‘text’,
‘width’ => ’70px’,
));
5. That’s it. Clear cache and check it from admin grid. Your custom column will show properly.

Some times your custom column value have you have show options values (ex:drop down value)”Yes” or “No” instead of 1 or 0:
Then follow below way,
1. Write your own query like above way
2. Add below code. Here “test” is my module name
$this->addColumn(‘customstatus’,
array(
‘header’ => ‘customstatus’,
‘align’ =>’center’,
‘index’ => ‘customstatus’,
‘type’  => ‘options’,
‘options’ => Mage::getSingleton(‘test/customstatus’)->getOptionArray(),
‘filter’    => false,        // This filed will help to show search box (text box in column) if it is true
‘sortable’  => false,        //onclick the column sorting option is disalbed in it is false

));
3. Create one model file name like customstatus.php
4. Add below code in this,

class Jute_Test_Model_Status extends Mage_Core_Model_Abstract
{
const CUSTOM_STATUS_YES    = 1;
const CUSTOM_STATUS_NO   = 0;

public function _construct()
{
parent::_construct();
$this->_init(‘test/status’);
}

static public function getOptionArray()
{
return array(
self::CUSTOM_STATUS_YES    => Mage::helper(‘test’)->__(‘YES’),
self::CUSTOM_STATUS_NO   => Mage::helper(‘test’)->__(‘NO’),
);
}
}

If Action want to give in your custom column then follow code like below
‘type’      => ‘action’,
‘actions’   => array(
array(
‘caption’ => Mage::helper(‘sales’)->__(‘View’),
‘url’     => array(‘base’=>’*/—-/—‘),    //Your action URL like Controller URL
‘field’   => ‘order_id’
)
),