我写了一个Magento网格扩展Mage_Adminhtml_Block_Widget_Grid,用于自定义管理客户页面。我需要排序多列默认情况下,然后我写_preparecall方法:
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是属性。但这行不通。我需要帮助,谢谢。
可以使用下面的代码
$collection->setOrder(array('customer_status', 'customer_type'), asc);