2012-12-17 17 views

回答

3

默認情況下,按照調用addColumn()的順序顯示列。你可以用函數addColumnAfter()來改變它。

以下代碼將在「entity_id」列後添加一個id爲「category_id」的列。 'entity_id'是列的id,而不是「索引」。這些都是99/100倍,但要注意。

$this->addColumnAfter('category_id',array(
     'header' => 'Category ID', 
     'index' => 'category_id', 
     'type' => 'text', 
     'width' => 70 
    ), 
    'entity_id' 
); 
0

通過使用addColumnAfter和/或addColumnOrder函數而不是addColumn

+0

使用兩者都會減少。通過調用addColumnAfter調用addColumn()然後addColumnsOrder()。您可以執行$ this-> addColumnAfter(...)或$ this-> addColumn(...),然後執行$ this-> addColumnsOrder(...)。最後它並不重要,但爲什麼要兩個電話,如果你可以在一個嗎? – Ian

+0

正確;我的回答措辭很差。我只是想記錄這兩個功能都可用。 – Ryre

0

使用$這個 - > addColumnAfter()而不是$這 - > addColumn()

$this->addColumnAfter('customattribute', array(
     'header'=> Mage::helper('customer')->__('customattribute'), 
     'index' => 'customattribute2', 
     'type' => 'options', 
     'options' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray(), 
     'width' => '100px', 
), 'before_grid_id'); 
0

$這個 - > sortColumnsByOrder(); _prepareColumns()函數的末尾有

protected function _prepareColumns() { 

    parent::_prepareColumns(); 

    $this->addColumnAfter('category_id', array(
     'header' => $this->__('Category ID'), 
     'index' => 'entity_id', 
     'type' => 'text', 
     'width' => 70 
    ), 'entity_id'); 

    $this->addColumnAfter('name', array(
     'header' => $this->__('Category name'), 
     'sortable' => true, 
     'index' => 'category_name'), 'entity_id'); 

    $this->sortColumnsByOrder(); 
    return $this; 
}