我为自定义管理客户页面编写了一个Magento网格扩展Mage_Adminhtml_Block_Widget_Grid。 我需要默认排序多个列,然后我写_prepareCollection方法:
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 :(得分:1)
您可以使用以下代码
$collection->setOrder(array('customer_status', 'customer_type'), asc);