在我的自定义模块中,我使用以下代码获得了网格视图。另外,我得到了正确的计数,但是网格只显示 1 行。即,它显示“共找到 2 条记录”,但在网格中只显示一行..
请帮忙。
我的自定义模块的 grid.php 代码如下:
public function __construct()
{
parent::__construct();
$this->setId(‘order_tailor’);
$this->setUseAjax(true);
}
/**
* Retrieve collection class
*
* @return string
*/
protected function _getCollectionClass()
{
return ‘sales/order_invoice_grid_collection’;
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->addFieldToSelect('entity_id')
->addFieldToSelect('order_id')
->setOrderFilter($this->getOrder())
;
$collection->getSelect()->join('custom_order_info', 'main_table.entity_id = custom_order_info.custom_id',array('tailor_name','created_at','custom_id','id'));
$collection->getSelect()->group('entity_id');
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn(‘id’, array(
‘header’ => Mage::helper(‘sales’)->__(‘ID’),
‘index’ => ‘id’,
‘width’ => ’120px’,
));
$this->addColumn(‘tailor_name’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Tailor Name’),
‘index’ => ‘tailor_name’,
));
$this->addColumn(‘created_at’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Date Sent’),
‘index’ => ‘created_at’,
‘type’ => ‘datetime’,
));
$this->addColumn(‘delivery_at’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Date Delivery Expected’),
‘index’ => ‘delivery_at’,
‘type’ => ‘datetime’,
));
$this->addColumn(‘status’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Status’),
‘index’ => ‘status’,
‘type’ => ‘options’,
‘options’ => array(
1 => ‘Draft’,
2 => ‘Sent’,
3 => ‘Accepted’,
),
));
$this->addColumn(‘base_grand_total’, array(
‘header’ => Mage::helper(‘customer’)->__(‘Amount’),
‘index’ => ‘base_grand_total’,
‘type’ => ‘currency’,
‘currency’ => ‘base_currency_code’,
));
return parent::_prepareColumns();
}
/**
* Retrieve order model instance
*
* @return Mage_Sales_Model_Order
*/
public function getOrder()
{
return Mage::registry(‘current_order’);
}
public function getRowUrl($row)
{
return $this->getUrl(‘*/sales_order_test/view’,
array(
‘id’ => $row->getId(),
‘order_id’ => $row->getOrderId()
)
);
}
public function getGridUrl()
{
return $this->getUrl(‘*/*/grid’, array(‘_current’ => true));
}