Palanikumar
Palanikumar

Reputation: 1746

How to add website field in magento admin grid?

Im creating a custom module for banner slider. In admin grid I want to display website field. For that in namespace/module/Block/Adminhtml/banner/Grid.php file I added

 if (!Mage::app()->isSingleStoreMode()) {
        $this->addColumn('website_id', array(
                'header'    => Mage::helper('bannerslider')->__('Website'),
                'align'     => 'center',
                'width'     => '80px',
                'type'      => 'options',
                'options'   => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
                'index'     => 'website_id',
        ));
      }

in _prepareColumns() function. Now I can able to see website column. But Im not able to see the website names in each rows. How can I show the website names in each rows. Please see the image.

enter image description here

What im missing?


Here is my collection.

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

I have a field called "website_id" in my table. Each row may have multiple values which are comma separated. In this situation can you tell me how to use collection?

Upvotes: 0

Views: 1660

Answers (2)

Thanh Tam Dang
Thanh Tam Dang

Reputation: 11

In the _prepareCollection() function, you insert :

parent::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();

Upvotes: 1

Tuong Le
Tuong Le

Reputation: 19230

If the website_id is in other tables..., you'll need to join the table and add the website_id in select, in the _prepareCollection() function.

protected function _prepareCollection() {
   //Your custom code in here
}

Upvotes: 0

Related Questions