Ngày xửa ngày xưa tôi đã thử tạo một số cột tùy chỉnh. Tôi đã tạo ra toàn bộ cấu trúc XML như tôi nên có. Tôi tạo ra bộ điều khiển. Tôi thậm chí đã tạo bộ điều khiển lưới tùy chỉnh.Sắp xếp cột lưới Magento
Sau khi tạo lưới tùy chỉnh của mình, tôi đã tìm các cột sẽ sắp xếp. Tôi đã sai, chết sai. Nhấp vào tiêu đề cột không làm gì cả.
Đề xuất?
class Company_Googlemerchant_Block_Adminhtml_Products_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('gm_product_grid');
$this->setDefaultSort('id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(false);
}
protected function _prepareCollection()
{
$storeId = 1;
$collection = Mage::getModel('catalog/product')->getCollection()->addStoreFilter($storeId);
$collection
->addAttributeToSelect('enable_googlemerchant')
->addAttributeToSelect('name')
->addAttributeToSelect('entity_id')
->addAttributeToSelect('type_id')
->addAttributeToSelect('status')
->addFieldToFilter('enable_googlemerchant', array("eq" => '1'))
->addFieldToFilter('status', array("eq" => '1'))
->addAttributeToSort('name', 'asc')
;
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('id', array(
'header' => Mage::helper('googlemerchant')->__('ID'),
'align' =>'left',
'index' => 'entity_id',
'width' => '100px',
));
$this->addColumn('product_name', array(
'header' => Mage::helper('googlemerchant')->__('Product Name'),
'align' =>'left',
'index' => 'name',
'width' => '250px',
));
$this->addColumn('type_id', array(
'header' => Mage::helper('googlemerchant')->__('Product Type'),
'align' =>'left',
'index' => 'type_id',
'width' => '100px',
));
$this->addColumn('action', array(
'header' => Mage::helper('googlemerchant')->__('Action'),
'width' => '100px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('googlemerchant')->__('Remove from export'),
'url' => array('base' => '*/*/removeexport'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => true,
'index' => 'id',
));
return parent::_prepareColumns();
}
}
Tôi nghĩ tôi khắc phục vấn đề bằng cách thay đổi 'setId ('gm_product_grid') 'với' setId ('adminhtml_products_grid') '. Tuy nhiên, sẽ đánh giá cao việc xác minh. –