谁能指出我如何在 Magento Grid 中保存可编辑列的正确方向?
我有一个名为 'sort_order' 的列,其中有 'editable' => true ,它添加了一个要编辑的字段,但是如何使它将值保存到行中?
预先感谢您的帮助。
这是我的 grid.php 代码,
class ***_Imagegallery_Block_Manage_Imagegallery_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('imagegalleryGrid');
$this->setDefaultSort('sort_order');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}
protected function _getStore()
{
$storeId = (int) $this->getRequest()->getParam('store', 0);
return Mage::app()->getStore($storeId);
}
protected function _prepareCollection()
{
$collection = Mage::getModel('imagegallery/imagegallery')->getCollection();
$store = $this->_getStore();
if ($store->getId()) {
$collection->addStoreFilter($store);
}
$filter = $this->getParam('filter');
$filter_data = Mage::helper('adminhtml')->prepareFilterString($filter);
if(!isset($filter_data['status']))
{
$collection->addFieldToFilter('status', array('eq' => 1));
}
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('sort_order', array(
'header' => Mage::helper('imagegallery')->__('Sort'),
'align' =>'right',
'width' => '50px',
'index' => 'sort_order',
'type' => 'number',
'width' => '1',
'sortable' => true,
'editable' => true
));
$this->addColumn('post_id', array(
'header' => Mage::helper('imagegallery')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'post_id',
));
$this->addColumn('nfile', array(
'header' => Mage::helper('cms')->__('Image File'),
'align' => 'left',
'index' => 'nfile',
'type' => 'image',
'width' => '100',
));
$this->addColumn('title', array(
'header' => Mage::helper('imagegallery')->__('Title'),
'align' =>'left',
'index' => 'title',
));
/*$this->addColumn('identifier', array(
'header' => Mage::helper('imagegallery')->__('Identifier'),
'align' => 'left',
'index' => 'identifier',
));
$this->addColumn('user', array(
'header' => Mage::helper('imagegallery')->__('Poster'),
'width' => '150px',
'index' => 'user',
));*/
$this->addColumn('created_time', array(
'header' => Mage::helper('imagegallery')->__('Created'),
'align' => 'left',
'width' => '120px',
'type' => 'date',
'default' => '--',
'index' => 'created_time',
));
$this->addColumn('update_time', array(
'header' => Mage::helper('imagegallery')->__('Updated'),
'align' => 'left',
'width' => '120px',
'type' => 'date',
'default' => '--',
'index' => 'update_time',
));
$this->addColumn('status', array(
'header' => Mage::helper('imagegallery')->__('Status'),
'align' => 'left',
'width' => '80px',
'index' => 'status',
'type' => 'options',
'options' => array(
1 => Mage::helper('imagegallery')->__('Enabled'),
2 => Mage::helper('imagegallery')->__('Disabled'),
3 => Mage::helper('imagegallery')->__('Hidden'),
),
));
$this->addColumn('action',
array(
'header' => Mage::helper('imagegallery')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('imagegallery')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
return parent::_prepareColumns();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('post_id');
$this->getMassactionBlock()->setFormFieldName('imagegallery');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('imagegallery')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('imagegallery')->__('Are you sure?')
));
$statuses = Mage::getSingleton('imagegallery/status')->getOptionArray();
array_unshift($statuses, array('label'=>'', 'value'=>''));
$this->getMassactionBlock()->addItem('status', array(
'label'=> Mage::helper('imagegallery')->__('Change status'),
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('imagegallery')->__('Status'),
'values' => $statuses
)
)
));
return $this;
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}
}