Akash Pius
Akash Pius

Reputation: 336

sorting and filtering not working in custom admin module

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

Thanks in advance.

Upvotes: 1

Views: 7715

Answers (3)

Deependra Singh
Deependra Singh

Reputation: 1514

Filter action is dependent on your below method:

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

now this is how you will prepare collection:

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);
...

Upvotes: 1

Akash Pius
Akash Pius

Reputation: 336

ok 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('*/*/transactiongrid', array('user_id',Mage::registry('merchant_data')->getId(), '_current' => true));
}

The correct method was

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

Upvotes: 1

Akash Pius
Akash Pius

Reputation: 336

When I dumped $regData I got this:

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

)

Upvotes: 0

Related Questions