I want to sort custom rendere column in magento grid.
See below image–
As in above image Sorting is done using Status column, but it is is showing wrong. I want to sort it like active
,on hold
,out of stock
.
Here is the code in Grid.php—
$this->addColumn('stock_status', array(
'header' => Mage::helper('allstock')->__('Status'),
'width' => '200px',
'align' => 'center',
'index' => 'stock_status',
'renderer' => 'allstock/adminhtml_allstock_renderer_stockstatus'
));
here is the renderer code-
public function render(Varien_Object $row)
{
$stock_status=$row->getStockStatus();
if($stock_status=='stock on hold')
{
$html="on hold";
}
else
{
$html=$stock_status;
}
return $html;
}
Best Answer
Finally I got my answer after working on it a lot, Here is How I made it possible-
Following links helped me alot--
https://stackoverflow.com/questions/5673093/sort-magento-collection-after-load https://stackoverflow.com/questions/7705007/magento-grid-sorting-on-rendered-column