magento adminhtml custom module it's showing the grid twice
Asked Answered
P

5

6

i am new to magento by following this guide Custom Module with Custom Database Table

i have implemented my already existed module to the backend adminhtml. i am taking stuff from the database and sjowing ot on the adminhtml page. Everything works ok except i am getting the grid twice on the adminhtml. i am getting the same Grid two time. i have looked the code for like 2 hours cannot figure it out. if anyone one knows how to fix this problem i will be greatly thakful. cheers

thats the code from my grid.php

<?php

      class Ecom_Pricenotify_Block_Adminhtml_Pricenotify_Grid extends Mage_Adminhtml_Block_Widget_Grid{
public function __construct()
{
    parent::__construct();
    $this->setId('pricenotifyGrid');
    // This is the primary key of the database
    $this->setDefaultSort('pricenotify_id');
    $this->setDefaultDir('ASC');
    $this->setSaveParametersInSession(true);
}

protected function _prepareCollection()
{
    $collection = Mage::getModel('pricenotify/pricenotify')->getCollection();
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

protected function _prepareColumns()
{
    $this->addColumn('pricenotify_id', array(
        'header'    => Mage::helper('pricenotify')->__('Notification ID'),
        'align'     =>'left',
        'width'     => '50px',
        'index'     => 'pricenotify_id',
    ));

    $this->addColumn('prod_id', array(
        'header'    => Mage::helper('pricenotify')->__('Product ID'),
        'align'     =>'left',
        'width'     => '50px',
        'index'     => 'prod_id',
    ));


    $this->addColumn('prod_price', array(
        'header'    => Mage::helper('pricenotify')->__('Product Price'),
        'align'     =>'left',
        'width'     => '50px',
        'index'     => 'prod_price',
    ));

    $this->addColumn('user_price', array(
        'header'    => Mage::helper('pricenotify')->__('User Price'),
        'align'     =>'left',
        'width'     => '50px',
        'index'     => 'user_price',
    ));

    $this->addColumn('email', array(
        'header'    => Mage::helper('pricenotify')->__('E-Mail Address'),
        'align'     =>'left',
        'width'     => '150px',
        'index'     => 'email',
    ));

    $this->addColumn('created_time', array(
        'header'    => Mage::helper('pricenotify')->__('Creation Time'),
        'align'     => 'left',
        'width'     => '120px',
        'type'      => 'date',
        'default'   => '--',
        'index'     => 'created_time',
    ));


    $this->addColumn('status', array(

        'header'    => Mage::helper('pricenotify')->__('Status'),
        'align'     => 'left',
        'width'     => '80px',
        'index'     => 'status',
        'type'      => 'options',
        'options'   => array(
            'success' => 'Inactive',
            'pending' => 'Active',
        ),
    ));

   return parent::_prepareColumns();
}

public function getRowUrl($row)
{
   return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}}

and this indexAction function is from the controller

  public function indexAction() {
    $this->_initAction();       
    $this->_addContent($this->getLayout()->createBlock('pricenotify/adminhtml_pricenotify'));
    $this->renderLayout();
  }
Pteropod answered 3/8, 2011 at 13:26 Comment(1)
Discover grid container or update your question with grid container and layout.xml.Dovap
J
6

Maybe you're inserting it in the layout, check pricenotify.xml in

adminhtml>default>default>layout.

Such as:

  <pricenotify_adminhtml_manager_pricenotify>
        <block type="core/text_list" name="root" output="toHtml">
            <block type="pricenotify/adminhtml_pricenotify_grid" name="pricenotify.grid"/>
        </block>
  </pricenotify_adminhtml_manager_pricenotify>

Remove this block or comment the line where you add the content.

Jodijodie answered 8/10, 2012 at 13:37 Comment(0)
P
4

I fixed it. i only had to comment out

//$this->_addContent($this->getLayout()->createBlock('pricenotify/adminhtml_pricenotify'));

from indexAction i guess iwas loading it twice.

Pteropod answered 4/8, 2011 at 6:23 Comment(1)
You should probably accept this answer to make it easier for other people to find.Skijoring
P
2

make sure that the grid block isn't already loaded in the corresponding layout.xml file.

Pantisocracy answered 3/8, 2011 at 15:9 Comment(0)
M
0

Well I was facing the same issue but in my case it was due to $this->setId('messages'); line (in your Grid.php construct). Because magento already has same <div id="messages"></div> in its grid page(for showing notifications) due to which my grid content was getting loaded within this 'div' tag hence showing grid twice. So lesson learned is don't give general name while setting your 'id' in Grid.php which could already be present in the grid page.

Merodach answered 13/10, 2015 at 8:53 Comment(0)
S
0

In my case, it's happened on Edit/Form, and I had duplicated unintentionally renderLayout() on my Adminhtml controller.

$this->renderLayout();
Striptease answered 1/3, 2016 at 0:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.