カスタム管理モジュールで機能していないソートとフィルタリング
-
16-10-2019 - |
質問
グリッドエンティティを編集しながら、最初のページにグリッドとタブにグリッドを備えたMagentoに管理モジュールを実装しようとしています。
メイングリッドは正常に機能しますが、タブのグリッドは正常に動作していません。
コードをデバッグしている間に見つけた問題は、フィールドフィルタリングでグリッド内のコレクションをロードしていることです。つまり、ユーザーIDであるフィルターでコレクションをフィルタリングしています。テーブルから1人のユーザーのデータのみが必要なので、これをしました。これにより問題が発生し、グリッド内のデータが正しく登場しますが、グリッド内のフィルタリング、ソート、検索機能は機能しておらず、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();
}
アップデート:
この問題には開発がありました。コードでいくつかの変更が行われることを知るようになりました。私は変更しました _prepareCollection()
以下:
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);//Getting the collection from the model. Here this is pointed to transactions table.
$this->setCollection($collection); //Set the collection
return parent::_prepareCollection();
}
と getGridUrl()
以下:
public function getGridUrl() {
return $this->getUrl('*/*/subscriptiongrid', array('user_id', Mage::registry('merchant_data')->getId(), '_current' => true));
}
現在、404エラーは表示されませんが、検索、フィルタリング、ソートのときにレコードは表示されません。戻ってきています null
値。私は持っています subscriptiongridAction
私のコントローラーで。以下はアクションです:
public function subscriptiongridAction() {
$this->loadLayout();
$this->getResponse()->setBody(
$this->getLayout()->createBlock('merchant/adminhtml_merchant_edit_tab_subscriptiongrid')->toHtml()
);
}
この問題を解決できるものは何ですか?
解決
私の問題は解決しました、私のコードに間違いがあります。グリッドファイルでは、以下の関数が間違っていました。
public function getGridUrl()
{
return $this->getUrl('*/*/subscriptiongrid', array('user_id', Mage::registry('merchant_data')->getId(), '_current' => true));
}
正しい方法は次のとおりです。
public function getGridUrl()
{
return $this->getUrl('*/*/subscriptiongrid', array('user_id' => Mage::registry('merchant_data')->getId(), '_current' => true));
}
他のヒント
一般的なエラーは、関数にグリッドURLを設定するのを忘れていることです getGridUrl()
の中に Grid.php
。関数は、グリッドURL自体を指す必要があります。
たとえば、URLを使用してグリッドにアクセスしている場合:
http://localhost:8010/magento/index.php/manager/adminhtml_index/user/
その後、対応します getGridUrl()
機能は次のとおりです。
public function getGridUrl() {
return $this->getUrl('*/*/user', array('_current' => true));
}