Magento – Magento 2: How to override UI component XML grid

magento2overridesuicomponent

I need to override sales_order_grid.xml from ui_component of Magento_Sales.

I want to remove some part of it but I don't know how to override it, I know how to override phtml from the custom module but for ui_component I have no idea.

[EDIT]

I will have multiple admin account, I don't want them to have access to some options and also I don't want them to see useless columns. The less thing they have to do the better it is.

[EDIT2]

Ok, i find that I can make in custom module the sales_order_grid.xml file under view/adminhtml/ui_component/. So this is the file :

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="sales_order_columns">
        <column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="filter" xsi:type="string">dateRange</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
                    <item name="dataType" xsi:type="string">date</item>
                    <item name="label" xsi:type="string" translate="true">Purchase Date</item>
                    <item name="dateFormat" xsi:type="string">MMM dd, YYYY, H:MM:SS A</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

As you can see, I try to set visible to false for created_at column.

Result : The column is still here, but not the filter panel like I show here :

enter image description here

Also, when I inspect element, and I set Display: none to the table, the block is here.

Best Answer

I was having the same issue while overriding sales_order_grid.xml from ui_component for me the below solution worked:

Add the <sequence> tag as shown in the example:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="CT_OrderCancel" setup_version="1.0.1" active="true">
        <sequence>
            <module name="Magento_Sales" />
        </sequence>
    </module>
</config>

Thanks.

Related Topic