سؤال

I am trying to implement an admin module in magento which has a grid in the first page and grids in the tabs while editing the grid entities.

The main grid works fine, but the grids in the tabs are not working fine.

The problem I found while I debugged the code is that, I am loading the collection in the grid with field filtering, ie I am filtering the collection with filter that is the user id. I did this because I need only data of a single user from the table. This made the entire problem, the data in the grid is coming correctly, but the filtering,sorting and searching feature inside grid is not working and returning a 404 not found error page. I tried removing the field filter I added while getting the collection, then it works fine but all the data in the table is coming which is the opposite to my requirement. Is there any possible solution to this. Here is the way I am trying to do:

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();
} 

UPDATE:

There has been a development in the issue. I came to know about some changes to be made in the code. I changed the _prepareCollection() to the following:

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();
}

and getGridUrl() to the following:

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

Now no 404 error shows, but when searching, filtering and sorting no records are shown. It's returning null values. I have subscriptiongridAction in my controller. Following is the action:

public function subscriptiongridAction() {
    $this->loadLayout();
    $this->getResponse()->setBody(
            $this->getLayout()->createBlock('merchant/adminhtml_merchant_edit_tab_subscriptiongrid')->toHtml()
    );
}

Any idea what could solve this issue?

هل كانت مفيدة؟

المحلول

My problem is solved, there is a mistake in my code. In the grid file the function below was wrong:

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

The correct method was:

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

نصائح أخرى

The common error is that we forget to set the grid URL in the function getGridUrl() in the Grid.php. The function should point to the grid URL itself.

For example if you are accessing grid using the URL:

http://localhost:8010/magento/index.php/manager/adminhtml_index/user/

Then corresponding getGridUrl() function will be:

public function getGridUrl() {
   return $this->getUrl('*/*/user', array('_current' => true));
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top