在我的自定义模块中,我使用下面的代码获得了网格视图。此外,我得到正确的计数,但网格只显示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));
}
答案 0 :(得分:1)
我认为您需要覆盖核心方法以获取网格中正确的计数和行数。如果您在Magento网格中的查询中使用“分组依据”,它有时无法正确处理它。我会建议检查我在这个问题上的帖子来解决它:
答案 1 :(得分:0)
我有同样的问题!我解决了它在config.xml中找到配置,我设置了不同的数据库资源!!那样:
<resources>
<home_write>
<connection>
<use>some_setup</use>
</connection>
</home_write>
<home_read>
<connection>
<use>some_setup</use>
</connection>
</home_read>
</resources>
我修改为default_setup,它解决了!