0

Can I show json data I pull from some api in admin grid? Currently I tried to create varien data collection. But its not working. Any help is highly appreciated.

class Company_Module_Block_Adminhtml_Poll_Grid extends Mage_Adminhtml_Block_Widget_Grid
{

    protected function _prepareCollection()
    {
        $collection = new Varien_Db_Collection();
        if ( Mage::registry('json_data') )
        {   
            $data=json_decode(Mage::registry('json_data'));         
            foreach ($data as $row) {
                $rowObj = new Varien_Object();
                $rowObj->setData($row);
                $collection->addItem($rowObj);
            }           
        }
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
    protected function _prepareColumns()
    {
        $this->addColumn('id', array(
            'type'=>'text',
            'index'=>'id',
            'header'=>$this->__('Print Id')
        ));
        $this->addColumn('customer_email', array(
            'type'=>'text',
            'index'=>'customer_email',
            'header'=>$this->__('Customer Email')
        ));
        return parent::_prepareColumns();
    }
}

1 Answer 1

3

Try this

Change collection class Varien_Db_Collection to Varien_Data_Collection

protected function _prepareCollection()
{
    $collection = new Varien_Data_Collection(); 
    if ( Mage::registry('json_data') )
    {   
        $data=json_decode(Mage::registry('json_data'));         
        foreach ($data as $row) {
            $rowObj = new Varien_Object();
            $rowObj->setData($row);
            $collection->addItem($rowObj);
        }           
    }
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
2
  • @Dushan you can upvote as well Feb 23, 2016 at 9:52
  • I need this but on M2 :( Don't know if I have to create Varien_Data_Collection too? and how?
    – Marc Pont
    Aug 4, 2017 at 13:50

Your Answer

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

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