3

I want to filter the order grid in admin to see only the orders in status "processing" in the grid by default.

enter image description here

This grid is different from the others, I tried solutions from here but no success

In magento 1 I have done this with an observer on "controller_action_predispatch_adminhtml_sales_order_index"

Do you have any idea on how to do that ?

Thanks you

EDIT 1 : This is the code I used in Magento 1 to do this with the event:

<controller_action_predispatch_adminhtml_sales_order_index>
                <observers>
                    <set_default_filter_sales_order>
                        <type>singleton</type>
                        <class>Gone_PreparedGridFilter_Model_Adminhtml_Sales_Order_Observer</class>
                        <method>setDefaultGridFilter</method>
                    </set_default_filter_sales_order>
                </observers>
            </controller_action_predispatch_adminhtml_sales_order_index>

And in my file :

public function setDefaultGridFilter(Varien_Event_Observer $observer)
        {
            $request = Mage::app()->getFrontController()->getRequest();

            if (! $request->getParam('filter')) {
                    $filter = $this->_getDefaultEncodedFilterString(); //custom function
                    Mage::app()->getFrontController()
                        ->getRequest()
                        ->setParam('filter', $filter);
            }

            return $this;
        }

My goal is to have the grid filtered by the status when you arrived on it but to be able to modify all filter including the status one.

Edit 2

Does anyone have a solution for this, I'm still looking for a solution. I don't want to use the grid view save tool.

2
  • Please share the code, what you done so far.. May 16, 2019 at 9:33
  • I tried multiple things: overload Magento\Backend\Block\Widget\Grid to add my filters, overload the grid collection. In the xml, adding a updater. I tried to modify the column to see if the is a node default filter value.
    – Taschert
    May 16, 2019 at 9:47

2 Answers 2

2

Update

For this use case there are two possible solutions

1. A simple non coding solution

Apply the Order Status Filter "Processing" in the Admin Order Grid then click on the "Default View" Tab and click the "Save view as" link, give the view a new name, say "Processing view" or any other name you wish. This will be set as a default view whenever you visit the order grid in subsequent page loads or admin login for the current user. The above solution works best if you have only single admin user.

Screenshot for your reference

https://prnt.sc/npo7hm

2. Solution via Custom Coding

After trying all other solutions listed in question links, i have derived the below solution for achieving the default filter for UI Component Admin Grid.

Override the sales_order_grid.xml in your custom module with the below codesnippet.

app/code/YourVendorPrefix/YourModuleName/view/adminhtml/ui_component/sales_order_grid.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<dataSource name="sales_order_grid_data_source" component="Magento_Ui/js/grid/provider">
    <settings>
        <filterUrlParams>
            <param name="status">processing</param>
        </filterUrlParams>
    </settings>
</dataSource>

The above xml code will filter the orders with the processing state. This will be applicable to all the admin users.

3
  • Thanks, i know I can do this like that but my issue is that it is not for all users. If I create a new admin account, this account won't have the filter by default. If he doesn't he might try to process an order he shouldn't have. Is it possible to force the default view for all user ?
    – Taschert
    May 17, 2019 at 7:01
  • See my updated answer to apply default filter via coding
    – mydons
    May 17, 2019 at 11:57
  • Nice one but when I do this the users won't be able do disable the filter to see all filter if the want. Is it possible to add the filterUrlParam only when there is no other filter ? I have added an example like i was doigt in M1
    – Taschert
    May 17, 2019 at 12:56
0

We can filter order grid by passing order status parameter in the url.

create a file sales_order_grid.xml on path, VendorName/ModuleName/view/adminhtml/ui_component

<dataSource name="sales_order_grid_data_source" component="Magento_Ui/js/grid/provider">
    <settings>
        <updateUrl path="mui/index/render"/>
        <filterUrlParams>
            <param name="status">*</param>
        </filterUrlParams>
    </settings>
</dataSource>

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.