Karan Adhikari
Karan Adhikari

Reputation: 60

Group by column value

I have created a custom module and in admin grid where i am calling module collection.

protected function _prepareCollection()
  {
    Mage::setIsDeveloperMode(true);
    ini_set('display_errors', 1);
    $collection = Mage::getModel('mymodule/custom')->getCollection();
    $this->setCollection($collection);
    return parent::_prepareCollection();
  } 

I want to use group by a column value in my module table..

I tried this

protected function _prepareCollection()
      {
        Mage::setIsDeveloperMode(true);
        ini_set('display_errors', 1);
        $collection = Mage::getModel('mymodule/custom')->getCollection()->getSelect()->group('column_2');
        $this->setCollection($collection);
        return parent::_prepareCollection();
      } 

but it doesn't work its throwing an error

Unrecognized method 'setPageSize()'

which i am not using anywhere in my grid.php

can anybody suggest me the problem with my code or solution of my problem

Upvotes: 0

Views: 53

Answers (2)

Check with this:

protected function _prepareCollection()
{
    Mage::setIsDeveloperMode(true);
    ini_set('display_errors', 1);
    $collection = Mage::getModel('mymodule/custom')->getCollection();
    $collection->getSelect()->group('column_2');
    $this->setCollection($collection);
    return parent::_prepareCollection();
} 

Upvotes: 1

Jitendra Patel
Jitendra Patel

Reputation: 373

//Try with below code.

$collection = Mage::getModel('mymodule/custom')->getCollection();
$collection->getSelect()->group('column_2');

Upvotes: 0

Related Questions