我正在尝试扩展Mage_Adminhtml_Block_Sales_Order_Grid
以添加新列。
我在sales_flat_order
' order_ready_for_dispatch
&#39;我希望在网格中显示的表格(<?xml version="1.0"?>
<config>
<global>
<modules>
<Sulman_SalesGrid>
<version>1.0.0</version>
</Sulman_SalesGrid>
</modules>
<blocks>
<adminhtml>
<rewrite>
<sales_order_grid>Sulman_SalesGrid_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
)(此字段单独添加/更新)。
问题是该列中没有显示数据,代码如下:
/app/code/local/Sulman/SalesGrid/etc/config.xml
<?php
class Sulman_SalesGrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _prepareCollection() {
$collection = parent::_prepareCollection()->getCollection();
$collection->addFieldToSelect('order_ready_for_dispatch');
return $this;
}
protected function _prepareColumns()
{
$this->addColumn('order_ready_for_dispatch', array(
'header'=> Mage::helper('sales')->__('Despatch Date'),
'width' => '80px',
'type' => 'text',
'index' => 'order_ready_for_dispatch',
));
return parent::_prepareColumns();
}
}
应用/代码/本地/萨勒曼/ SalesGrid /砌块/ Adminhtml /销售/订购/ Grid.php
for(i=0;i<formFields.length;i++)
{
if(formFields[i]!= 'hidden field')
then formFields[i].show();
}
任何人都可以看到我的错误吗?谢谢:)
答案 0 :(得分:2)
好的,所以我通过改变_prepareCollection()
方法来实现它:
protected function _prepareCollection(){
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id', array('order_ready_for_dispatch'));
$this->setCollection($collection);
return $this;
}