2016-11-07 62 views
1

我编写了一个Magento网格扩展Mage_Adminhtml_Block_Widget_Grid,用于自定义管理客户页面。 我在默认情况下需要排序多列,那么我写_prepareCollection方法:默认Magento自定义管理网格页面中的多个排序列

protected function _prepareCollection() 
    { 
    $collection = Mage::getResourceModel('customer/customer_collection') 
    ->addNameToSelect() 
    ->addAttributeToSelect('customer_type') 
    ->addAttributeToSelect('email') 
    ->addAttributeToSelect('created_at') 
    ->addAttributeToSelect('group_id')  
    ->addAttributeToSelect('customer_status')  
    ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left') 
    ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left') 
    ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left') 
    ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left') 
    ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left') 
      ->addAttributeToSort('customer_status', 'asc') 
      ->addAttributeToSort('customer_type', 'asc'); 
    $this->setCollection($collection); 

    return parent::_prepareCollection(); 
    } 

注意customer_status和CUSTOMER_TYPE都是属性。 但它不起作用。我需要帮助,谢谢。

回答

0

您可以使用下面的代码

$collection->setOrder(array('customer_status', 'customer_type'), asc); 
+0

好,谢谢你,那工作 –