4

Is it possible to have multiple collections in one grid? Suppose if we have grouped data, and we need to display it in multiple dynamic child grids.

Suppose data is:

firstname lastname city
Group 1: 
mark      james     new york
mark      james     new york

Group 2:
mark      james     california
mark      james     california

Group 3 :
aston    wright     france
aston    liam       france

Is it possible?

4
  • os is it possible to pass parameter(collection) in controller and looping the admin grid to get multiple grids on same page?
    – Guru
    Commented Jun 27, 2013 at 18:24
  • How do you group the collection? It is loaded from one table? If collection items is loaded from one table and you want to display them as grouped visually, it is not too hard task. Please, clarify your situation more.
    – mageUz
    Commented Jun 28, 2013 at 7:54
  • Thanks mageUz. please check this code$collections =Mage::getSingleton('mergeaccount/data')->getGroups();$collection_of_things = new Varien_Data_Collection();foreach($collections as $collection) {$collection_of_things->addItem($collection);}$this->setCollection($collection_o‌​f_things);return parent::_prepareCollection(); where $collections is array of Mage::getModel('customer/customer')->getCollection()->addFieldToFilter($attribut‌​enames[0], array('eq'=>$arrrayData[$k][$attributenames[0]]));
    – Guru
    Commented Jun 28, 2013 at 14:31
  • Above code gives me error "it gives error "Fatal error: Call to a member function append() on a non-object". Please let me know where am i going wrong? Thanks again :)
    – Guru
    Commented Jun 28, 2013 at 14:31

1 Answer 1

4

You may add several grids to the page.

Otherwise you will need to create some sort of compound collection in _prepareCollection method. In this case, you'd better create some new model which would be dealing with data.

16
  • Thanks for the answer. Could you please explain little more. i used this code but it did not work ( i used loop to set collections) $collections =Mage::getSingleton('mergeaccount/data')->getGroups(); foreach($collections as $collection) { $this->setCollection($collection); } return parent::_prepareCollection(); Could you please paste code for compound collection? and also is it possible to pass parameters from controller and iterate grid block in controller? Thanks in advance:)
    – Guru
    Commented Jun 27, 2013 at 21:28
  • could someone explain it little more? if possible with an exmaple. Thanks a lot :)
    – Guru
    Commented Jun 28, 2013 at 5:44
  • In your example $this->setCollection($collection) will use only data from last one. You need to combine them though. If your data are in different tables you will probably need to add them into Varien_Data_Collection object with addItem. Item to be added is Varien_Object. So you do $item = new Varien_Object(), then $item->addData($arr) and $varienCollection->addItem($item). Something like this. That all should be done in you model, where you take your data from various sources and create new collection.
    – Taras
    Commented Jun 28, 2013 at 11:17
  • this link may help.
    – Taras
    Commented Jun 28, 2013 at 11:43
  • Thanks again for the answer. i used this code. $collections =Mage::getSingleton('mergeaccount/data')->getGroups();$collection_of_things = new Varien_Data_Collection();foreach($collections as $collection) {$collection_of_things->addItem($collection);}$this->setCollection($collection_of_things);return parent::_prepareCollection(); where $collections is array of Mage::getModel('customer/customer')->getCollection()->addFieldToFilter($attributenames[0], array('eq'=>$arrrayData[$k][$attributenames[0]]));
    – Guru
    Commented Jun 28, 2013 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.