1

How to display all product attribute in my custom grid i am using the below code but its returning results in array format can you please correct me where i am doing wrong

 $this->addColumn('action',
            array(
                'header'    =>  Mage::helper('kems')->__('Magento Attribute'),
                'width'     => '100',
                'align'     => 'center',
                'type'      => 'select',
                'getter'    => 'getId',
                'renderer'  => 'Kensium_Kems_Block_Adminhtml_Renderer_Attribute',
                'filter'    => false,
                'sortable'  => false,
                'index'     => 'magento_attribute',
                'is_system' => true,
            ));

===================================================

public function render(Varien_Object $row)
    {

    $url ='';
    $html =array();

    $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
                                        ->getItems();

    foreach ($attributes as $attribute){

     $html[] = $attribute->getFrontendLabel();

    }

   //echo '<pre>';
   print_r($html);
    //die;
    return array_keys($html);
}

1 Answer 1

1

here i can give you concept to make drop down in grid not your full solution

you can return array like this with help of below function

 public function toOptionArray()
    {
$columns = array(
    array(
        'value' => 'id',   
        'label' => __('ID')
    ),

);

$columnsCollection = 
    Mage::getResourceModel('eav/entity_attribute_collection')
    ->setEntityTypeFilter( Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId() )
->addFilter("is_visible", 1);

foreach($columnsCollection->getItems() as $column) 
{
    $columns[] = array(
        'value' => $column->getAttributeCode(),   
        'label' => $column->getFrontendLabel()
    );
}

    return $columns;
}

EDIT For select box

instead of using renderer you can also use select box in grid like below

$columnsCollection = 
        Mage::getResourceModel('eav/entity_attribute_collection')
        ->setEntityTypeFilter( Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId() )
    ->addFilter("is_visible", 1);

    foreach($columnsCollection->getItems() as $column) 
    {
        $columns[$column->getAttributeCode()] =  $column->getFrontendLabel();
    }


  $this->addColumn('your_attribute', array(
            'header' => Mage::helper('modulename')->__('Your attribute'),
            'index' => 'your_attribute',
            'type' => 'options',
            'options'=> $columns;
            ));

But as i seen in your question you are going to add Action.. Dont know why you have to add this attribute dropdown in action

2
  • Hi liyakat thanks for the solution but above solution is not working in my condition .I need to show all product attribute in my custom grid only
    – Magento AJ
    Commented Feb 19, 2015 at 10:16
  • @MagentoAJ, use my updated asnwer and also see magento.stackexchange.com/questions/10317/…
    – liyakat
    Commented Feb 19, 2015 at 10:39

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.