1

在我的自定义模块中,我使用以下代码获得了网格视图。另外,我得到了正确的计数,但是网格只显示 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));
}
4

2 回答 2

1

I think you will need to override a core method to get correct count and rows in grid. If you are using "group by" in your query in Magento grid, it sometimes doesn't handle it properly. I will recommend to check my post on this issue to fix it:

http://ka.lpe.sh/2012/01/05/magento-wrong-count-in-admin-grid-when-using-group-by-clause-overriding-lib-module/

于 2013-01-28T10:56:39.077 回答
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,它解决了!

于 2015-04-17T08:55:06.147 回答