1

This is my code:

   $this->addColumn(
       $key,
       array(
           header' => Mage::helper('core')->__($key),
           'index' => $key,
           'filter' => 'adminhtml/widget_grid_column_filter_select',
           'sortable' => true,
       )
   );      

I want to get all of the values from my column and put it in the dropdown options values and to filter them. Is there a way to do that ? At the moment I got an empty dropdown.

[UPDATE]

For instance if my values are 2,3,2,3,4,5,6,7 . I want to have in my dropdown the following values: 2,3,4,5,6,7

[UPDATE 2]

I managed to put the values in the dropdown. See My code:

$this->addColumn(
    $key,
    array(
       'header' => Mage::helper('core')->__($key),
       'index' => $key,
       'filter' => 'adminhtml/widget_grid_column_filter_select',
       'sortable' => true,
       'renderer' => $render,
       'type'      => 'options',
       'options'   => $this->_getOrderType(),
      )
);
public function _getOrderType(){
        $types = new Varien_Object(array(
            "Frontend" => "Frontend",
            "AdminPanel" => "AdminPanel"
        ));
        return $types->getData();
}

But my filter doesn't work. If I filter after smth I got an empty grid. enter image description here

[UPDATE 3]

Update with the render function:

public function render(Varien_Object $row)
    {
        $value = $this->_getValue($row);
        if ($value == ""){
            return "Frontend";
        }else {
            return "AdminPanel";
        }
    }

2 Answers 2

0

I am not sure where the values come from, but you can use native's php array_unique function on the array of values, so the options would be unique.

7
  • can you check my post again, i made some updates. thx Jul 6, 2016 at 12:49
  • I don't completely understand what you are trying to achieve here, sorry. But to answer your update - try adding the custom filter callback as described in here: magento.stackexchange.com/questions/21313/… Jul 6, 2016 at 13:08
  • Can you check my image that I attached. I just want to make a filter after the values from my dropdown. At the moment with my code , doesn;t work and I do not know why . Can you help me ? thx in advance :) Jul 6, 2016 at 13:14
  • What is your $render variable? Can you update the post with the renderer? Jul 6, 2016 at 13:17
  • Check now I did . If my row is empty show Frontend otherwise show Adminpanel Jul 6, 2016 at 13:21
0

You can simply use as below

$this->addColumn($key, array(
        'header' => Mage::helper('core')->__($key),
        'align' => 'left',
        'width' => '80px',
        'index' => 'status',
        'type' => 'options',
        'options' => array(
            'Frontend' => 'Frontend',
            'Admin' => 'Admin'
        )
    ));

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.