Using 2.1.3, is there a way to hide an entire column from a UI component admin grid? I found Magento2 Add css class to admin ui grid column, and that hides the column, but not the column header (misaligning the grid columns).
3 Answers
use <item name="visible" xsi:type="boolean">false</item>
in the config node of data argument when declaring column
eg.
<column name="created_at">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="resizeEnabled" xsi:type="boolean">false</item>
<item name="filter" xsi:type="string">dateRange</item>
<item name="sorting" xsi:type="string">desc</item>
<item name="label" xsi:type="string" translate="true">Created at</item>
<item name="sortOrder" xsi:type="number">120</item>
<item name="visible" xsi:type="boolean">false</item>
</item>
</argument>
</column>
the only issue that the filter won't showing until you switch the column back to visible
-
Thanks @Mammouth, but this looks like a config setting - I want to be able to change the visibility based on the users role, so it would have to check it in code.– dbcnCommented Jun 16, 2017 at 17:18
-
acl wasn't created for this ... but for mimic something similar just extend/override
Magento_Ui/view/base/web/js/grid/columns/column.js
with your business logic– MammouthCommented Jun 20, 2017 at 10:33 -
otehrwise I think would be good to open a new thread to your current problem (hiding column by user role settings), because this one already solved– MammouthCommented Jun 20, 2017 at 10:43
-
@Mammouth, But the filter should visible, only can we hide from column? Commented Feb 20, 2020 at 11:36
You can try with <item name="componentDisabled" xsi:type="boolean">true</item>
For example:
Vendor/Module/view/adminhtml/ui_component/product_form.xml
<field name="backorders">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</argument>
</field>
-
Thanks @Khoa, but I want to display the column depending on the user's permissions, so I want the column there, but to start hidden.– dbcnCommented Feb 7, 2017 at 16:41
Add below code in your ui xml to remove columns
<column name="name_of_column">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</argument>
</column>
<field name="name_of_column">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</argument>
</field>