2013-12-16 52 views
1

我想在magento中實現一個管理模塊,它在編輯網格實體時在第一頁和網格中有一個網格。排序和過濾不工作在自定義管理模塊

主網格工作正常,但標籤中的網格工作不正常。

我在調試代碼時發現的問題是,我正在使用字段過濾加載網格中的集合,即我使用用戶標識過濾器來過濾集合。我這樣做是因爲我只需要表中的單個用戶的數據。這造成了整個問題,網格中的數據會正確顯示,但網格內的篩選,排序和搜索功能無法正常工作,並返回404未找到的錯誤頁面。我嘗試刪除我在獲取集合時添加的字段過濾器,然後它可以正常工作,但表中的所有數據都將到達,這與我的要求相反。 有沒有任何可能的解決方案。這是我想要做的方式:

protected function _prepareCollection() { 
     $collection = Mage::getModel('merchant/subscriptions')->getCollection()->addFieldToFilter('user_id', Mage::registry('merchant_data')->getId()); 
     $this->setCollection($collection); //Set the collection 
     return parent::_prepareCollection(); 
    } 

在此先感謝。

回答

1

好我的問題解決了我的代碼中有一個錯誤。在網格文件中,下面的函數是錯誤的。

public function getGridUrl() { 
    return $this->getUrl('*/*/transactiongrid', array('user_id',Mage::registry('merchant_data')->getId(), '_current' => true)); 
} 

正確的方法是

public function getGridUrl() { 
    return $this->getUrl('*/*/transactiongrid', array('user_id'=> Mage::registry('merchant_data')->getId(), '_current' => true)); 
} 
+0

你在答案中寫的兩個函數有什麼區別? – Muk

+1

在我在'user_id'後面傳遞的參數中,我首先添加了逗號,實際上它必須是'=>'。這個函數有兩個參數,我通過了三個參數。 –

1

過濾作用依賴於你的下面的方法:

public function getGridUrl() { 
    return $this->getUrl('*/*/grid', array('user_id' => Mage::registry('merchant_data')->getId(),'_current'=>true)); 
} 

現在這是你將如何準備集合:

protected function _prepareCollection() 
{ 
    $regData = Mage::registry('merchant_data'); 
    if(isset($regData)) 
       $regData = $regData->getId(); 
    else 
     $regData = $this->getRequest()->getParam('user_id'); 
    $collection = Mage::getModel('merchant/subscriptions')->getCollection()->addFieldToFilter('user_id',$regData); 
... 
+0

感謝它真的幫助。 –

+0

雖然有一個問題.404未找到錯誤現在不會發生, 但排序,過濾和搜索後的結果返回null。什麼會引起這個@Deependra Singh –

+0

你可以檢查你的*/*/grid'動作,然後在'_prepareCollection()'中確認你每次都正確地獲得了$ regData。 –

0

當我甩$ REGDATA我得到這個:

Cubet_Merchant_Model_Merchant Object 
(
    [_eventPrefix:protected] => core_abstract 
    [_eventObject:protected] => object 
    [_resourceName:protected] => merchant/merchant 
    [_resource:protected] => 
    [_resourceCollectionName:protected] => merchant/merchant_collection 
    [_cacheTag:protected] => 
    [_dataSaveAllowed:protected] => 1 
    [_isObjectNew:protected] => 
    [_data:protected] => Array 
     (
      [user_id] => 3 
      [firstname] => Robin 
      [lastname] => Cubet 
      [email] => [email protected] 
      [username] => robincubet 
      [password] => 51a7f45eb11fc49b5967a0039193c3ad:HSX8JkSO5lr3uaRHrzd86i7gb0RATeDb 
      [created] => 2013-12-12 08:34:28 
      [modified] => 2013-12-16 09:03:56 
      [logdate] => 
      [lognum] => 0 
      [reload_acl_flag] => 1 
      [is_active] => 1 
      [extra] => N; 
      [rp_token] => 
      [rp_token_created_at] => 
     ) 

    [_hasDataChanges:protected] => 
    [_origData:protected] => Array 
     (
      [user_id] => 3 
      [firstname] => Robin 
      [lastname] => Cubet 
      [email] => [email protected] 
      [username] => robincubet 
      [password] => 51a7f45eb11fc49b5967a0039193c3ad:HSX8JkSO5lr3uaRHrzd86i7gb0RATeDb 
      [created] => 2013-12-12 08:34:28 
      [modified] => 2013-12-16 09:03:56 
      [logdate] => 
      [lognum] => 0 
      [reload_acl_flag] => 1 
      [is_active] => 1 
      [extra] => N; 
      [rp_token] => 
      [rp_token_created_at] => 
     ) 

    [_idFieldName:protected] => user_id 
    [_isDeleted:protected] => 
    [_oldFieldsMap:protected] => Array 
     (
     ) 

    [_syncFieldsMap:protected] => Array 
     (
     ) 

) 
相關問題