How do I add a custom dropdown filter in a grid












0















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";
}
}









share|improve this question





























    0















    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";
    }
    }









    share|improve this question



























      0












      0








      0








      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";
      }
      }









      share|improve this question
















      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";
      }
      }






      magento-1 grid filter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 6 '16 at 13:20







      Attila Naghi

















      asked Jul 6 '16 at 12:22









      Attila NaghiAttila Naghi

      374418




      374418






















          1 Answer
          1






          active

          oldest

          votes


















          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.






          share|improve this answer


























          • can you check my post again, i made some updates. thx

            – Attila Naghi
            Jul 6 '16 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/…

            – Wladyslaw Brodsky
            Jul 6 '16 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 :)

            – Attila Naghi
            Jul 6 '16 at 13:14











          • What is your $render variable? Can you update the post with the renderer?

            – Wladyslaw Brodsky
            Jul 6 '16 at 13:17











          • Check now I did . If my row is empty show Frontend otherwise show Adminpanel

            – Attila Naghi
            Jul 6 '16 at 13:21











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f124488%2fhow-do-i-add-a-custom-dropdown-filter-in-a-grid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          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.






          share|improve this answer


























          • can you check my post again, i made some updates. thx

            – Attila Naghi
            Jul 6 '16 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/…

            – Wladyslaw Brodsky
            Jul 6 '16 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 :)

            – Attila Naghi
            Jul 6 '16 at 13:14











          • What is your $render variable? Can you update the post with the renderer?

            – Wladyslaw Brodsky
            Jul 6 '16 at 13:17











          • Check now I did . If my row is empty show Frontend otherwise show Adminpanel

            – Attila Naghi
            Jul 6 '16 at 13:21
















          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.






          share|improve this answer


























          • can you check my post again, i made some updates. thx

            – Attila Naghi
            Jul 6 '16 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/…

            – Wladyslaw Brodsky
            Jul 6 '16 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 :)

            – Attila Naghi
            Jul 6 '16 at 13:14











          • What is your $render variable? Can you update the post with the renderer?

            – Wladyslaw Brodsky
            Jul 6 '16 at 13:17











          • Check now I did . If my row is empty show Frontend otherwise show Adminpanel

            – Attila Naghi
            Jul 6 '16 at 13:21














          0












          0








          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 6 '16 at 12:57









          Rushvi

          2,4091729




          2,4091729










          answered Jul 6 '16 at 12:44









          Wladyslaw BrodskyWladyslaw Brodsky

          617




          617













          • can you check my post again, i made some updates. thx

            – Attila Naghi
            Jul 6 '16 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/…

            – Wladyslaw Brodsky
            Jul 6 '16 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 :)

            – Attila Naghi
            Jul 6 '16 at 13:14











          • What is your $render variable? Can you update the post with the renderer?

            – Wladyslaw Brodsky
            Jul 6 '16 at 13:17











          • Check now I did . If my row is empty show Frontend otherwise show Adminpanel

            – Attila Naghi
            Jul 6 '16 at 13:21



















          • can you check my post again, i made some updates. thx

            – Attila Naghi
            Jul 6 '16 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/…

            – Wladyslaw Brodsky
            Jul 6 '16 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 :)

            – Attila Naghi
            Jul 6 '16 at 13:14











          • What is your $render variable? Can you update the post with the renderer?

            – Wladyslaw Brodsky
            Jul 6 '16 at 13:17











          • Check now I did . If my row is empty show Frontend otherwise show Adminpanel

            – Attila Naghi
            Jul 6 '16 at 13:21

















          can you check my post again, i made some updates. thx

          – Attila Naghi
          Jul 6 '16 at 12:49





          can you check my post again, i made some updates. thx

          – Attila Naghi
          Jul 6 '16 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/…

          – Wladyslaw Brodsky
          Jul 6 '16 at 13:08





          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/…

          – Wladyslaw Brodsky
          Jul 6 '16 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 :)

          – Attila Naghi
          Jul 6 '16 at 13:14





          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 :)

          – Attila Naghi
          Jul 6 '16 at 13:14













          What is your $render variable? Can you update the post with the renderer?

          – Wladyslaw Brodsky
          Jul 6 '16 at 13:17





          What is your $render variable? Can you update the post with the renderer?

          – Wladyslaw Brodsky
          Jul 6 '16 at 13:17













          Check now I did . If my row is empty show Frontend otherwise show Adminpanel

          – Attila Naghi
          Jul 6 '16 at 13:21





          Check now I did . If my row is empty show Frontend otherwise show Adminpanel

          – Attila Naghi
          Jul 6 '16 at 13:21


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f124488%2fhow-do-i-add-a-custom-dropdown-filter-in-a-grid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1300-talet

          1300-talet

          Display a custom attribute below product name in the front-end Magento 1.9.3.8