Aug 25, 2011

Magento: GRID Important functions

Adding Edit link on a row


protected function _prepareColumns()
{
// .... Some other code here
$this->addColumn('action',
array(
'header' => Mage::helper('catalog')->__('Action'),
'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('catalog')->__('Edit'),
'url' => array(
'base'=>'*/*/edit',
'params'=>array(),
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
)
);
}


Removing the Pager/Filter


Normally this is default on the magento grid already.

public function __construct()
{
parent::__construct();
$this->setFilterVisibility(false); // Remove Seach filtering
$this->setPagerVisibility(false); // Remove Pager of the grid
}


Adding Mass proccess on the Grid



protected function _prepareMassaction()
{
$this->setMassactionIdField('trans_id');
//$this->getMassactionBlock()->setFormFieldName('download');
$this->getMassactionBlock()->addItem('delete', array(
'label'=> Mage::helper('download')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('download')->__('Are you sure?')
));

$this->getMassactionBlock()->addItem('status', array(
'label'=> Mage::helper('download')->__('Change status'),
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('download')->__('Status'),
'values' => array("x1" => "Yow", "x2"=>"secret")
)
)
));
}

No comments: