To add default filter to grid in Magento2?Magento 2 : How can I load an admin grid with pre-defined filter...

Why is Agricola named as such?

Why zero tolerance on nudity in space?

Can we harness gravitational potential energy?

I will be going to Sweden on business purpose .Can I visit London from Sweden and how much UK visa will cost?

How can animals be objects of ethics without being subjects as well?

Does a phylactery of a lich have to be a box?

How can I get my players to come to the game session after agreeing to a date?

How can i do a custom maintenance message on magento 2.2.4

What's a good word to describe a public place that looks like it wouldn't be rough?

Eww, those bytes are gross

Why is it that Bernie Sanders is always called a "socialist"?

use of 4/2 chord more compelling than root position?

Difference between i++ and (i)++ in C

The use of the spellings -zz- vs. -z-

When can a QA tester start his job?

What does it mean for a caliber to be flat shooting?

Use two 8s and two 3s to make the number 24

Quickly creating a sparse array

Which one of these password policies are more secure?

What is the wife of a henpecked husband called?

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

How much mayhem could I cause as a sentient fish?

Bash Script Function Return True-False

Can a person refuse a presidential pardon?



To add default filter to grid in Magento2?


Magento 2 : How can I load an admin grid with pre-defined filter values?Default filtering in UI Component GridMagento 2 - Customize Customer Grid Collection DataMagento 2 adminhtml custom column sorting ascending and descendingmagento 2 apply a custom filter in the gridAdd default custom_attribute filter to product grid in Magento 2.1Filter admin grid based on the url parameterHow to use addFieldToFilter on ui gridMagento 2 Filter admin grid collection by defaultAdmin personal module routes failedWhy isn't magento finding my adminhtml grid block?How can i rewrite TierPrice Block in Magento2add default filter for admin grid magento2Magento 2 Custom module admin controller errorMagento column grid default filter valueMagento 2 Add new field to Magento_User admin formUncaught Error: Call to a member function setItem() on boolean on product grid: Magento 2Filter Custom Grid CollectionMulti select filter in magento2 grid













10















I have created one custom module with title & status field attribute in admin grid.



Grid collections in module_test_grid_block.xml



        <arguments>
<argument name="id" xsi:type="string">testGrid</argument>
<argument name="dataSource" xsi:type="object">NamespaceModuleModelResourceModeltestCollection</argument>
<argument name="default_sort" xsi:type="string">id</argument>
<argument name="default_dir" xsi:type="string">desc</argument>
<argument name="grid_url" xsi:type="url" path="*/*/grid"><param name="_current">1</param></argument>
</arguments>


I want to show the data which are enabled. Have any option to add default filter in admin grid collections?



EDIT



    <block class="NamespaceModuleBlockAdminhtmlTestGrid" name="namespace_module_test.grid" as="grid">
<arguments>
<argument name="id" xsi:type="string">testGrid</argument>
<argument name="dataSource" xsi:type="object">NamespaceModuleModelResourceModeltestCollection</argument>
<argument name="default_sort" xsi:type="string">id</argument>
<argument name="default_dir" xsi:type="string">desc</argument>
<argument name="grid_url" xsi:type="url" path="*/*/grid"><param name="_current">1</param></argument>
<argument name="default_filter" xsi:type="array">
<item name="status" xsi:type="string">1</item>
</argument>
</arguments>
.
.
</block>


In Block - Grid.php



    namespace NamespaceModuleBlockAdminhtmlTest;

use MagentoBackendBlockWidgetGrid as WidgetGrid;

class Grid extends WidgetGrid
{
public function _construct()
{
parent::_construct();
if ($this->hasData('default_filter')) {
// print_r($this->getData('default_filter'));die;
$this->setDefaultFilter($this->getData('default_filter'));
}
}
}


I have followed this link to create admin grid in magento 2



http://www.mage-world.com/blog/grid-and-form-in-magento-2-admin-panel-part-1.html










share|improve this question





























    10















    I have created one custom module with title & status field attribute in admin grid.



    Grid collections in module_test_grid_block.xml



            <arguments>
    <argument name="id" xsi:type="string">testGrid</argument>
    <argument name="dataSource" xsi:type="object">NamespaceModuleModelResourceModeltestCollection</argument>
    <argument name="default_sort" xsi:type="string">id</argument>
    <argument name="default_dir" xsi:type="string">desc</argument>
    <argument name="grid_url" xsi:type="url" path="*/*/grid"><param name="_current">1</param></argument>
    </arguments>


    I want to show the data which are enabled. Have any option to add default filter in admin grid collections?



    EDIT



        <block class="NamespaceModuleBlockAdminhtmlTestGrid" name="namespace_module_test.grid" as="grid">
    <arguments>
    <argument name="id" xsi:type="string">testGrid</argument>
    <argument name="dataSource" xsi:type="object">NamespaceModuleModelResourceModeltestCollection</argument>
    <argument name="default_sort" xsi:type="string">id</argument>
    <argument name="default_dir" xsi:type="string">desc</argument>
    <argument name="grid_url" xsi:type="url" path="*/*/grid"><param name="_current">1</param></argument>
    <argument name="default_filter" xsi:type="array">
    <item name="status" xsi:type="string">1</item>
    </argument>
    </arguments>
    .
    .
    </block>


    In Block - Grid.php



        namespace NamespaceModuleBlockAdminhtmlTest;

    use MagentoBackendBlockWidgetGrid as WidgetGrid;

    class Grid extends WidgetGrid
    {
    public function _construct()
    {
    parent::_construct();
    if ($this->hasData('default_filter')) {
    // print_r($this->getData('default_filter'));die;
    $this->setDefaultFilter($this->getData('default_filter'));
    }
    }
    }


    I have followed this link to create admin grid in magento 2



    http://www.mage-world.com/blog/grid-and-form-in-magento-2-admin-panel-part-1.html










    share|improve this question



























      10












      10








      10


      0






      I have created one custom module with title & status field attribute in admin grid.



      Grid collections in module_test_grid_block.xml



              <arguments>
      <argument name="id" xsi:type="string">testGrid</argument>
      <argument name="dataSource" xsi:type="object">NamespaceModuleModelResourceModeltestCollection</argument>
      <argument name="default_sort" xsi:type="string">id</argument>
      <argument name="default_dir" xsi:type="string">desc</argument>
      <argument name="grid_url" xsi:type="url" path="*/*/grid"><param name="_current">1</param></argument>
      </arguments>


      I want to show the data which are enabled. Have any option to add default filter in admin grid collections?



      EDIT



          <block class="NamespaceModuleBlockAdminhtmlTestGrid" name="namespace_module_test.grid" as="grid">
      <arguments>
      <argument name="id" xsi:type="string">testGrid</argument>
      <argument name="dataSource" xsi:type="object">NamespaceModuleModelResourceModeltestCollection</argument>
      <argument name="default_sort" xsi:type="string">id</argument>
      <argument name="default_dir" xsi:type="string">desc</argument>
      <argument name="grid_url" xsi:type="url" path="*/*/grid"><param name="_current">1</param></argument>
      <argument name="default_filter" xsi:type="array">
      <item name="status" xsi:type="string">1</item>
      </argument>
      </arguments>
      .
      .
      </block>


      In Block - Grid.php



          namespace NamespaceModuleBlockAdminhtmlTest;

      use MagentoBackendBlockWidgetGrid as WidgetGrid;

      class Grid extends WidgetGrid
      {
      public function _construct()
      {
      parent::_construct();
      if ($this->hasData('default_filter')) {
      // print_r($this->getData('default_filter'));die;
      $this->setDefaultFilter($this->getData('default_filter'));
      }
      }
      }


      I have followed this link to create admin grid in magento 2



      http://www.mage-world.com/blog/grid-and-form-in-magento-2-admin-panel-part-1.html










      share|improve this question
















      I have created one custom module with title & status field attribute in admin grid.



      Grid collections in module_test_grid_block.xml



              <arguments>
      <argument name="id" xsi:type="string">testGrid</argument>
      <argument name="dataSource" xsi:type="object">NamespaceModuleModelResourceModeltestCollection</argument>
      <argument name="default_sort" xsi:type="string">id</argument>
      <argument name="default_dir" xsi:type="string">desc</argument>
      <argument name="grid_url" xsi:type="url" path="*/*/grid"><param name="_current">1</param></argument>
      </arguments>


      I want to show the data which are enabled. Have any option to add default filter in admin grid collections?



      EDIT



          <block class="NamespaceModuleBlockAdminhtmlTestGrid" name="namespace_module_test.grid" as="grid">
      <arguments>
      <argument name="id" xsi:type="string">testGrid</argument>
      <argument name="dataSource" xsi:type="object">NamespaceModuleModelResourceModeltestCollection</argument>
      <argument name="default_sort" xsi:type="string">id</argument>
      <argument name="default_dir" xsi:type="string">desc</argument>
      <argument name="grid_url" xsi:type="url" path="*/*/grid"><param name="_current">1</param></argument>
      <argument name="default_filter" xsi:type="array">
      <item name="status" xsi:type="string">1</item>
      </argument>
      </arguments>
      .
      .
      </block>


      In Block - Grid.php



          namespace NamespaceModuleBlockAdminhtmlTest;

      use MagentoBackendBlockWidgetGrid as WidgetGrid;

      class Grid extends WidgetGrid
      {
      public function _construct()
      {
      parent::_construct();
      if ($this->hasData('default_filter')) {
      // print_r($this->getData('default_filter'));die;
      $this->setDefaultFilter($this->getData('default_filter'));
      }
      }
      }


      I have followed this link to create admin grid in magento 2



      http://www.mage-world.com/blog/grid-and-form-in-magento-2-admin-panel-part-1.html







      admin magento2 collection grid






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 mins ago









      Saravanan DS

      494624




      494624










      asked Dec 29 '15 at 13:36









      DRAJIDRAJI

      52531637




      52531637






















          4 Answers
          4






          active

          oldest

          votes


















          11





          +50









          If you define grid collection thought layout than you can use updater to add default filter.



          <argument name="dataSource" xsi:type="object">
          TutorialSimpleNewsModelResourceNewsCollection
          <updater>TutorialSimpleNewsModelResourceNewsCollectionUpdater</updater>
          </argument>


          and



          <?php
          namespace TutorialSimpleNewsModelResourceNewsCollection;

          class CollectionUpdater implements MagentoFrameworkViewLayoutArgumentUpdaterInterface
          {

          /**
          * Update grid collection according to chosen order
          *
          * @param TutorialSimpleNewsModelResourceNewsCollection $argument
          * @return TutorialSimpleNewsModelResourceNewsCollection
          */
          public function update($argument)
          {
          $argument->addFieldToFilter('you_field', 'value');

          return $argument;
          }
          }


          or Extend Grid block



          class Grid extends MagentoBackendBlockWidgetGrid
          {
          protected function _prepareCollection()
          {
          if ($this->getCollection()) {
          foreach ($this->getDefaultFilter() as $field => $value) {
          $this->getCollection()->addFieldToFilter($field, $value);
          }
          }
          return parent::_prepareCollection();
          }
          }





          share|improve this answer


























          • Hi KAndy, It's not working for me. Could you help me to sort it out ??

            – Vigna S
            Sep 6 '16 at 7:04








          • 1





            To anyone finding this answer, please note that it only applies to legacy grids. Not UI-component based grids.

            – Andre Klang
            Jun 11 '18 at 6:59











          • So, how can we apply this type of filters to ui-component based grid?

            – Knight017
            Jan 2 at 17:42



















          4














          you need to add this inside the arguments tag:



          <argument name="default_filter" xsi:type="array">
          <item name="field_name_here" xsi:type="string">value here</item>
          </argument>


          if your arguments are contained in this block



          <block class="MagentoBackendBlockWidgetGrid" name="some.name.here" as="grid">


          you need to create your own class that extends MagentoBackendBlockWidgetGrid like this:



          <?php 
          namespace NamespaceModuleBlockAdminhtmlWhatever;

          class Grid extends MagentoBackendBlockWidgetGrid
          {
          public function _construct()
          {
          parent::_construct();
          if ($this->hasData('default_filter')) {
          $this->setDefaultFilter($this->getData('default_filter'));
          }
          }
          }


          and modify the block tag above to



           <block class="NamespaceModuleBlockAdminhtmlWhateverGrid" name="some.name.here" as="grid">


          if you already use a custom grid and not the default MagentoBackendBlockWidgetGrid you don't need to create the class.

          You just need to copy the _construct method from above in your class.






          share|improve this answer
























          • Hi @Marius , Thank you for your response. In construct method i got default filter value. But filtering not working. Not too get all records

            – DRAJI
            Jan 13 '16 at 11:11






          • 1





            maybe you should add more code you have to the question to get a better overview.

            – Marius
            Jan 13 '16 at 11:12











          • I have updated my question with filter code what i added

            – DRAJI
            Jan 13 '16 at 11:27











          • Great. I will take a new look and come back with a result.

            – Marius
            Jan 13 '16 at 11:28











          • Hi Marius, I tried this but it's not working, have you found any solution?

            – Vigna S
            Sep 6 '16 at 5:48



















          0














          here is the reference on devdocs:



          http://devdocs.magento.com/guides/v2.0/ui-components/ui-secondary-filter.html



          If You need more info on that - you can create a pull request or an issue via docs page - just click "Edit this page on GitHub" link. Docs are constantly updated and improved.






          share|improve this answer





















          • 1





            the link you mentioned shows how to add filters in a grid that uses the ui components. I think the question is about changing a grid that extends MagentoBackendBlockWidgetGrid. But I may be wrong.

            – Marius
            Jan 13 '16 at 9:16













          • Hi @EquinoxBlack Thank you for your response. But it by using UI component

            – DRAJI
            Jan 13 '16 at 11:10



















          0














          After trying many codes which doesn't work, finally find a way doesn't need coding - make use of saving custom views function which could save filter and column settings.



          Specific steps



          After setting filter and column settings, click on the Default View button with the eye icon, then click Save View As… to enter a name for your view. Then you could click the custom view whenever you want to get the grid just the way you like it, and you can save custom views as many as you like.



          You can also go back and use the edit icon to rename it or delete it later on, or to return to the default view.



          I think this is a very good function in Magento 2 :)



          enter image description here






          share|improve this answer























            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%2f95371%2fto-add-default-filter-to-grid-in-magento2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            11





            +50









            If you define grid collection thought layout than you can use updater to add default filter.



            <argument name="dataSource" xsi:type="object">
            TutorialSimpleNewsModelResourceNewsCollection
            <updater>TutorialSimpleNewsModelResourceNewsCollectionUpdater</updater>
            </argument>


            and



            <?php
            namespace TutorialSimpleNewsModelResourceNewsCollection;

            class CollectionUpdater implements MagentoFrameworkViewLayoutArgumentUpdaterInterface
            {

            /**
            * Update grid collection according to chosen order
            *
            * @param TutorialSimpleNewsModelResourceNewsCollection $argument
            * @return TutorialSimpleNewsModelResourceNewsCollection
            */
            public function update($argument)
            {
            $argument->addFieldToFilter('you_field', 'value');

            return $argument;
            }
            }


            or Extend Grid block



            class Grid extends MagentoBackendBlockWidgetGrid
            {
            protected function _prepareCollection()
            {
            if ($this->getCollection()) {
            foreach ($this->getDefaultFilter() as $field => $value) {
            $this->getCollection()->addFieldToFilter($field, $value);
            }
            }
            return parent::_prepareCollection();
            }
            }





            share|improve this answer


























            • Hi KAndy, It's not working for me. Could you help me to sort it out ??

              – Vigna S
              Sep 6 '16 at 7:04








            • 1





              To anyone finding this answer, please note that it only applies to legacy grids. Not UI-component based grids.

              – Andre Klang
              Jun 11 '18 at 6:59











            • So, how can we apply this type of filters to ui-component based grid?

              – Knight017
              Jan 2 at 17:42
















            11





            +50









            If you define grid collection thought layout than you can use updater to add default filter.



            <argument name="dataSource" xsi:type="object">
            TutorialSimpleNewsModelResourceNewsCollection
            <updater>TutorialSimpleNewsModelResourceNewsCollectionUpdater</updater>
            </argument>


            and



            <?php
            namespace TutorialSimpleNewsModelResourceNewsCollection;

            class CollectionUpdater implements MagentoFrameworkViewLayoutArgumentUpdaterInterface
            {

            /**
            * Update grid collection according to chosen order
            *
            * @param TutorialSimpleNewsModelResourceNewsCollection $argument
            * @return TutorialSimpleNewsModelResourceNewsCollection
            */
            public function update($argument)
            {
            $argument->addFieldToFilter('you_field', 'value');

            return $argument;
            }
            }


            or Extend Grid block



            class Grid extends MagentoBackendBlockWidgetGrid
            {
            protected function _prepareCollection()
            {
            if ($this->getCollection()) {
            foreach ($this->getDefaultFilter() as $field => $value) {
            $this->getCollection()->addFieldToFilter($field, $value);
            }
            }
            return parent::_prepareCollection();
            }
            }





            share|improve this answer


























            • Hi KAndy, It's not working for me. Could you help me to sort it out ??

              – Vigna S
              Sep 6 '16 at 7:04








            • 1





              To anyone finding this answer, please note that it only applies to legacy grids. Not UI-component based grids.

              – Andre Klang
              Jun 11 '18 at 6:59











            • So, how can we apply this type of filters to ui-component based grid?

              – Knight017
              Jan 2 at 17:42














            11





            +50







            11





            +50



            11




            +50





            If you define grid collection thought layout than you can use updater to add default filter.



            <argument name="dataSource" xsi:type="object">
            TutorialSimpleNewsModelResourceNewsCollection
            <updater>TutorialSimpleNewsModelResourceNewsCollectionUpdater</updater>
            </argument>


            and



            <?php
            namespace TutorialSimpleNewsModelResourceNewsCollection;

            class CollectionUpdater implements MagentoFrameworkViewLayoutArgumentUpdaterInterface
            {

            /**
            * Update grid collection according to chosen order
            *
            * @param TutorialSimpleNewsModelResourceNewsCollection $argument
            * @return TutorialSimpleNewsModelResourceNewsCollection
            */
            public function update($argument)
            {
            $argument->addFieldToFilter('you_field', 'value');

            return $argument;
            }
            }


            or Extend Grid block



            class Grid extends MagentoBackendBlockWidgetGrid
            {
            protected function _prepareCollection()
            {
            if ($this->getCollection()) {
            foreach ($this->getDefaultFilter() as $field => $value) {
            $this->getCollection()->addFieldToFilter($field, $value);
            }
            }
            return parent::_prepareCollection();
            }
            }





            share|improve this answer















            If you define grid collection thought layout than you can use updater to add default filter.



            <argument name="dataSource" xsi:type="object">
            TutorialSimpleNewsModelResourceNewsCollection
            <updater>TutorialSimpleNewsModelResourceNewsCollectionUpdater</updater>
            </argument>


            and



            <?php
            namespace TutorialSimpleNewsModelResourceNewsCollection;

            class CollectionUpdater implements MagentoFrameworkViewLayoutArgumentUpdaterInterface
            {

            /**
            * Update grid collection according to chosen order
            *
            * @param TutorialSimpleNewsModelResourceNewsCollection $argument
            * @return TutorialSimpleNewsModelResourceNewsCollection
            */
            public function update($argument)
            {
            $argument->addFieldToFilter('you_field', 'value');

            return $argument;
            }
            }


            or Extend Grid block



            class Grid extends MagentoBackendBlockWidgetGrid
            {
            protected function _prepareCollection()
            {
            if ($this->getCollection()) {
            foreach ($this->getDefaultFilter() as $field => $value) {
            $this->getCollection()->addFieldToFilter($field, $value);
            }
            }
            return parent::_prepareCollection();
            }
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 17 '16 at 9:01

























            answered Jan 15 '16 at 19:50









            KAndyKAndy

            15.8k23044




            15.8k23044













            • Hi KAndy, It's not working for me. Could you help me to sort it out ??

              – Vigna S
              Sep 6 '16 at 7:04








            • 1





              To anyone finding this answer, please note that it only applies to legacy grids. Not UI-component based grids.

              – Andre Klang
              Jun 11 '18 at 6:59











            • So, how can we apply this type of filters to ui-component based grid?

              – Knight017
              Jan 2 at 17:42



















            • Hi KAndy, It's not working for me. Could you help me to sort it out ??

              – Vigna S
              Sep 6 '16 at 7:04








            • 1





              To anyone finding this answer, please note that it only applies to legacy grids. Not UI-component based grids.

              – Andre Klang
              Jun 11 '18 at 6:59











            • So, how can we apply this type of filters to ui-component based grid?

              – Knight017
              Jan 2 at 17:42

















            Hi KAndy, It's not working for me. Could you help me to sort it out ??

            – Vigna S
            Sep 6 '16 at 7:04







            Hi KAndy, It's not working for me. Could you help me to sort it out ??

            – Vigna S
            Sep 6 '16 at 7:04






            1




            1





            To anyone finding this answer, please note that it only applies to legacy grids. Not UI-component based grids.

            – Andre Klang
            Jun 11 '18 at 6:59





            To anyone finding this answer, please note that it only applies to legacy grids. Not UI-component based grids.

            – Andre Klang
            Jun 11 '18 at 6:59













            So, how can we apply this type of filters to ui-component based grid?

            – Knight017
            Jan 2 at 17:42





            So, how can we apply this type of filters to ui-component based grid?

            – Knight017
            Jan 2 at 17:42













            4














            you need to add this inside the arguments tag:



            <argument name="default_filter" xsi:type="array">
            <item name="field_name_here" xsi:type="string">value here</item>
            </argument>


            if your arguments are contained in this block



            <block class="MagentoBackendBlockWidgetGrid" name="some.name.here" as="grid">


            you need to create your own class that extends MagentoBackendBlockWidgetGrid like this:



            <?php 
            namespace NamespaceModuleBlockAdminhtmlWhatever;

            class Grid extends MagentoBackendBlockWidgetGrid
            {
            public function _construct()
            {
            parent::_construct();
            if ($this->hasData('default_filter')) {
            $this->setDefaultFilter($this->getData('default_filter'));
            }
            }
            }


            and modify the block tag above to



             <block class="NamespaceModuleBlockAdminhtmlWhateverGrid" name="some.name.here" as="grid">


            if you already use a custom grid and not the default MagentoBackendBlockWidgetGrid you don't need to create the class.

            You just need to copy the _construct method from above in your class.






            share|improve this answer
























            • Hi @Marius , Thank you for your response. In construct method i got default filter value. But filtering not working. Not too get all records

              – DRAJI
              Jan 13 '16 at 11:11






            • 1





              maybe you should add more code you have to the question to get a better overview.

              – Marius
              Jan 13 '16 at 11:12











            • I have updated my question with filter code what i added

              – DRAJI
              Jan 13 '16 at 11:27











            • Great. I will take a new look and come back with a result.

              – Marius
              Jan 13 '16 at 11:28











            • Hi Marius, I tried this but it's not working, have you found any solution?

              – Vigna S
              Sep 6 '16 at 5:48
















            4














            you need to add this inside the arguments tag:



            <argument name="default_filter" xsi:type="array">
            <item name="field_name_here" xsi:type="string">value here</item>
            </argument>


            if your arguments are contained in this block



            <block class="MagentoBackendBlockWidgetGrid" name="some.name.here" as="grid">


            you need to create your own class that extends MagentoBackendBlockWidgetGrid like this:



            <?php 
            namespace NamespaceModuleBlockAdminhtmlWhatever;

            class Grid extends MagentoBackendBlockWidgetGrid
            {
            public function _construct()
            {
            parent::_construct();
            if ($this->hasData('default_filter')) {
            $this->setDefaultFilter($this->getData('default_filter'));
            }
            }
            }


            and modify the block tag above to



             <block class="NamespaceModuleBlockAdminhtmlWhateverGrid" name="some.name.here" as="grid">


            if you already use a custom grid and not the default MagentoBackendBlockWidgetGrid you don't need to create the class.

            You just need to copy the _construct method from above in your class.






            share|improve this answer
























            • Hi @Marius , Thank you for your response. In construct method i got default filter value. But filtering not working. Not too get all records

              – DRAJI
              Jan 13 '16 at 11:11






            • 1





              maybe you should add more code you have to the question to get a better overview.

              – Marius
              Jan 13 '16 at 11:12











            • I have updated my question with filter code what i added

              – DRAJI
              Jan 13 '16 at 11:27











            • Great. I will take a new look and come back with a result.

              – Marius
              Jan 13 '16 at 11:28











            • Hi Marius, I tried this but it's not working, have you found any solution?

              – Vigna S
              Sep 6 '16 at 5:48














            4












            4








            4







            you need to add this inside the arguments tag:



            <argument name="default_filter" xsi:type="array">
            <item name="field_name_here" xsi:type="string">value here</item>
            </argument>


            if your arguments are contained in this block



            <block class="MagentoBackendBlockWidgetGrid" name="some.name.here" as="grid">


            you need to create your own class that extends MagentoBackendBlockWidgetGrid like this:



            <?php 
            namespace NamespaceModuleBlockAdminhtmlWhatever;

            class Grid extends MagentoBackendBlockWidgetGrid
            {
            public function _construct()
            {
            parent::_construct();
            if ($this->hasData('default_filter')) {
            $this->setDefaultFilter($this->getData('default_filter'));
            }
            }
            }


            and modify the block tag above to



             <block class="NamespaceModuleBlockAdminhtmlWhateverGrid" name="some.name.here" as="grid">


            if you already use a custom grid and not the default MagentoBackendBlockWidgetGrid you don't need to create the class.

            You just need to copy the _construct method from above in your class.






            share|improve this answer













            you need to add this inside the arguments tag:



            <argument name="default_filter" xsi:type="array">
            <item name="field_name_here" xsi:type="string">value here</item>
            </argument>


            if your arguments are contained in this block



            <block class="MagentoBackendBlockWidgetGrid" name="some.name.here" as="grid">


            you need to create your own class that extends MagentoBackendBlockWidgetGrid like this:



            <?php 
            namespace NamespaceModuleBlockAdminhtmlWhatever;

            class Grid extends MagentoBackendBlockWidgetGrid
            {
            public function _construct()
            {
            parent::_construct();
            if ($this->hasData('default_filter')) {
            $this->setDefaultFilter($this->getData('default_filter'));
            }
            }
            }


            and modify the block tag above to



             <block class="NamespaceModuleBlockAdminhtmlWhateverGrid" name="some.name.here" as="grid">


            if you already use a custom grid and not the default MagentoBackendBlockWidgetGrid you don't need to create the class.

            You just need to copy the _construct method from above in your class.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 13 '16 at 9:35









            MariusMarius

            166k28317677




            166k28317677













            • Hi @Marius , Thank you for your response. In construct method i got default filter value. But filtering not working. Not too get all records

              – DRAJI
              Jan 13 '16 at 11:11






            • 1





              maybe you should add more code you have to the question to get a better overview.

              – Marius
              Jan 13 '16 at 11:12











            • I have updated my question with filter code what i added

              – DRAJI
              Jan 13 '16 at 11:27











            • Great. I will take a new look and come back with a result.

              – Marius
              Jan 13 '16 at 11:28











            • Hi Marius, I tried this but it's not working, have you found any solution?

              – Vigna S
              Sep 6 '16 at 5:48



















            • Hi @Marius , Thank you for your response. In construct method i got default filter value. But filtering not working. Not too get all records

              – DRAJI
              Jan 13 '16 at 11:11






            • 1





              maybe you should add more code you have to the question to get a better overview.

              – Marius
              Jan 13 '16 at 11:12











            • I have updated my question with filter code what i added

              – DRAJI
              Jan 13 '16 at 11:27











            • Great. I will take a new look and come back with a result.

              – Marius
              Jan 13 '16 at 11:28











            • Hi Marius, I tried this but it's not working, have you found any solution?

              – Vigna S
              Sep 6 '16 at 5:48

















            Hi @Marius , Thank you for your response. In construct method i got default filter value. But filtering not working. Not too get all records

            – DRAJI
            Jan 13 '16 at 11:11





            Hi @Marius , Thank you for your response. In construct method i got default filter value. But filtering not working. Not too get all records

            – DRAJI
            Jan 13 '16 at 11:11




            1




            1





            maybe you should add more code you have to the question to get a better overview.

            – Marius
            Jan 13 '16 at 11:12





            maybe you should add more code you have to the question to get a better overview.

            – Marius
            Jan 13 '16 at 11:12













            I have updated my question with filter code what i added

            – DRAJI
            Jan 13 '16 at 11:27





            I have updated my question with filter code what i added

            – DRAJI
            Jan 13 '16 at 11:27













            Great. I will take a new look and come back with a result.

            – Marius
            Jan 13 '16 at 11:28





            Great. I will take a new look and come back with a result.

            – Marius
            Jan 13 '16 at 11:28













            Hi Marius, I tried this but it's not working, have you found any solution?

            – Vigna S
            Sep 6 '16 at 5:48





            Hi Marius, I tried this but it's not working, have you found any solution?

            – Vigna S
            Sep 6 '16 at 5:48











            0














            here is the reference on devdocs:



            http://devdocs.magento.com/guides/v2.0/ui-components/ui-secondary-filter.html



            If You need more info on that - you can create a pull request or an issue via docs page - just click "Edit this page on GitHub" link. Docs are constantly updated and improved.






            share|improve this answer





















            • 1





              the link you mentioned shows how to add filters in a grid that uses the ui components. I think the question is about changing a grid that extends MagentoBackendBlockWidgetGrid. But I may be wrong.

              – Marius
              Jan 13 '16 at 9:16













            • Hi @EquinoxBlack Thank you for your response. But it by using UI component

              – DRAJI
              Jan 13 '16 at 11:10
















            0














            here is the reference on devdocs:



            http://devdocs.magento.com/guides/v2.0/ui-components/ui-secondary-filter.html



            If You need more info on that - you can create a pull request or an issue via docs page - just click "Edit this page on GitHub" link. Docs are constantly updated and improved.






            share|improve this answer





















            • 1





              the link you mentioned shows how to add filters in a grid that uses the ui components. I think the question is about changing a grid that extends MagentoBackendBlockWidgetGrid. But I may be wrong.

              – Marius
              Jan 13 '16 at 9:16













            • Hi @EquinoxBlack Thank you for your response. But it by using UI component

              – DRAJI
              Jan 13 '16 at 11:10














            0












            0








            0







            here is the reference on devdocs:



            http://devdocs.magento.com/guides/v2.0/ui-components/ui-secondary-filter.html



            If You need more info on that - you can create a pull request or an issue via docs page - just click "Edit this page on GitHub" link. Docs are constantly updated and improved.






            share|improve this answer















            here is the reference on devdocs:



            http://devdocs.magento.com/guides/v2.0/ui-components/ui-secondary-filter.html



            If You need more info on that - you can create a pull request or an issue via docs page - just click "Edit this page on GitHub" link. Docs are constantly updated and improved.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 12 '16 at 15:43









            7ochem

            5,77293768




            5,77293768










            answered Jan 12 '16 at 15:37









            EquinoxBlackEquinoxBlack

            11




            11








            • 1





              the link you mentioned shows how to add filters in a grid that uses the ui components. I think the question is about changing a grid that extends MagentoBackendBlockWidgetGrid. But I may be wrong.

              – Marius
              Jan 13 '16 at 9:16













            • Hi @EquinoxBlack Thank you for your response. But it by using UI component

              – DRAJI
              Jan 13 '16 at 11:10














            • 1





              the link you mentioned shows how to add filters in a grid that uses the ui components. I think the question is about changing a grid that extends MagentoBackendBlockWidgetGrid. But I may be wrong.

              – Marius
              Jan 13 '16 at 9:16













            • Hi @EquinoxBlack Thank you for your response. But it by using UI component

              – DRAJI
              Jan 13 '16 at 11:10








            1




            1





            the link you mentioned shows how to add filters in a grid that uses the ui components. I think the question is about changing a grid that extends MagentoBackendBlockWidgetGrid. But I may be wrong.

            – Marius
            Jan 13 '16 at 9:16







            the link you mentioned shows how to add filters in a grid that uses the ui components. I think the question is about changing a grid that extends MagentoBackendBlockWidgetGrid. But I may be wrong.

            – Marius
            Jan 13 '16 at 9:16















            Hi @EquinoxBlack Thank you for your response. But it by using UI component

            – DRAJI
            Jan 13 '16 at 11:10





            Hi @EquinoxBlack Thank you for your response. But it by using UI component

            – DRAJI
            Jan 13 '16 at 11:10











            0














            After trying many codes which doesn't work, finally find a way doesn't need coding - make use of saving custom views function which could save filter and column settings.



            Specific steps



            After setting filter and column settings, click on the Default View button with the eye icon, then click Save View As… to enter a name for your view. Then you could click the custom view whenever you want to get the grid just the way you like it, and you can save custom views as many as you like.



            You can also go back and use the edit icon to rename it or delete it later on, or to return to the default view.



            I think this is a very good function in Magento 2 :)



            enter image description here






            share|improve this answer




























              0














              After trying many codes which doesn't work, finally find a way doesn't need coding - make use of saving custom views function which could save filter and column settings.



              Specific steps



              After setting filter and column settings, click on the Default View button with the eye icon, then click Save View As… to enter a name for your view. Then you could click the custom view whenever you want to get the grid just the way you like it, and you can save custom views as many as you like.



              You can also go back and use the edit icon to rename it or delete it later on, or to return to the default view.



              I think this is a very good function in Magento 2 :)



              enter image description here






              share|improve this answer


























                0












                0








                0







                After trying many codes which doesn't work, finally find a way doesn't need coding - make use of saving custom views function which could save filter and column settings.



                Specific steps



                After setting filter and column settings, click on the Default View button with the eye icon, then click Save View As… to enter a name for your view. Then you could click the custom view whenever you want to get the grid just the way you like it, and you can save custom views as many as you like.



                You can also go back and use the edit icon to rename it or delete it later on, or to return to the default view.



                I think this is a very good function in Magento 2 :)



                enter image description here






                share|improve this answer













                After trying many codes which doesn't work, finally find a way doesn't need coding - make use of saving custom views function which could save filter and column settings.



                Specific steps



                After setting filter and column settings, click on the Default View button with the eye icon, then click Save View As… to enter a name for your view. Then you could click the custom view whenever you want to get the grid just the way you like it, and you can save custom views as many as you like.



                You can also go back and use the edit icon to rename it or delete it later on, or to return to the default view.



                I think this is a very good function in Magento 2 :)



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 27 '17 at 3:11









                Key ShangKey Shang

                1,6611135




                1,6611135






























                    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%2f95371%2fto-add-default-filter-to-grid-in-magento2%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

                    “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                    How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                    變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...