2015-06-30 121 views
0

您好我已經在出貨電網增加了一個新的列如下過濾數據

$this->addColumn('telephone', array(
    'header' => Mage::helper('sales')->__('Billing Phone'), 
    'index' => 'telephone', 

    'renderer'=> new OSP_Adminhtml_Block_Customer_Renderer_BillingPhone() 
    )); 
在此

我使用的是渲染器顯示自定義的值如下

public function render(Varien_Object $row) { 
     $customer_id = $row->getData('customer_id'); 

    if($customer_id > 0) { 
     // get member_id (club canon) 
     $customer = Mage::getModel('customer/customer')->load($customer_id); 
     if(is_object($customer)) { 
      $value = $customer->getData('mobile'); 
     } 
    }else{ 
    $id = $row->getData('order_increment_id'); 
    $order = Mage::getModel('sales/order')->loadByIncrementId($id); 
    $value = $order->getBillingAddress()->getTelephone(); 
} 
    return $value; 
} 

哪個工作正常,它在渲染器中的 條件的基礎上正確顯示數據。

但問題是,現在我還需要過濾數據,這是不 工作,因爲它看起來的數據僅作爲一個電話列或移動 我看了一下filter_condition_callback,但無法使工作。你能建議我怎麼做這項工作。

在此先感謝

回答

0

1.新增線路filter_condition_callback列,這樣的:

$this->addColumn('telephone', array(
    'header' => Mage::helper('sales')->__('Billing Phone'), 
    'index' => 'telephone', 
    'filter_condition_callback' => array($this, '_someCallBackFunction'), 
    'renderer'=> new OSP_Adminhtml_Block_Customer_Renderer_BillingPhone() 
    )); 

當你添加在您的專欄這一行,的Magento會調用這個回調函數,在看app/code/core/Mage/Adminhtml/Block/Widget/Grid.php 468行。

2.In您塊網格文件創建_someCallBackFunction功能,這將需要兩個參數,$collection - 未加載集合對象,並$columnMage_Adminhtml_Block_Widget_Grid_Column

protected function _someCallBackFunction($collection, $column) 
{ 
    $value = $column->getFilter()->getValue(); 
    if ($value === null) { //here check if filter is not null 
     return $this; 
    } 

    /** 
    * Here you can add filter to collection 
    * or do other manipulations with collection. 
    * As example you can check filter value and filter collection. 
    */ 
    if ($value != 0) { 
     $collection->addFieldToFilter('telephone', array('neq' => 0)); 
    } 

    return $this; 
} 
+0

是那是什麼,我想知道我怎麼能做到這一點。 –

+0

看我在我的答案中扔了幾步。 – sergio

+0

我的意思是在回撥功能,我無法在收藏中添加過濾器你能幫我那個。感謝 –