Here, I am using layout xml file to render block grid columns, but facing issue to render specific column on condition basis, here I want to show/hide column on basis of user role but not able to do this.
Please help me with this problem, how can I achieve this?
I am sharing my layout xml file code:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="supplier.order.grid.container">
<block class="Magento\Backend\Block\Widget\Grid" name="supplier.grid" as="grid">
<arguments>
<argument name="id" xsi:type="string">purchaseOrderGrid</argument>
<argument name="dataSource" xsi:type="object">Vendor\Module\Model\ResourceModel\Order\Collection</argument>
<argument name="use_ajax" xsi:type="string">1</argument>
<argument name="default_sort" xsi:type="string">po_id</argument>
<argument name="default_dir" xsi:type="string">desc</argument>
<argument name="grid_url" xsi:type="url" path="*/*/orderGrid"/>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\ColumnSet" as="grid.columnSet" name="permission.user.grid.columnSet">
<arguments>
<argument name="id" xsi:type="string">purchaseOrderGrid</argument>
<argument name="rowUrl" xsi:type="array">
<item name="generatorClass" xsi:type="string">Magento\Backend\Model\Widget\Grid\Row\UrlGenerator</item>
<item name="path" xsi:type="string">*/*/edit</item>
<item name="extraParamsTemplate" xsi:type="array">
<item name="po_id" xsi:type="string">getId</item>
</item>
</argument>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_id">
<arguments>
<argument name="header" xsi:type="string" translate="true">ID</argument>
<argument name="sortable" xsi:type="string">true</argument>
<argument name="index" xsi:type="string">po_id</argument>
<argument name="column_css_class" xsi:type="string">col-id</argument>
<argument name="header_css_class" xsi:type="string">col-id</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_reference">
<arguments>
<argument name="header" xsi:type="string" translate="true">Reference</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="index" xsi:type="string">po_reference</argument>
<argument name="escape" xsi:type="string">1</argument>
<argument name="column_css_class" xsi:type="string">col-name</argument>
<argument name="header_css_class" xsi:type="string">col-name</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_sup_id">
<arguments>
<argument name="header" xsi:type="string" translate="true">Supplier</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="options" model="Vendor\Module\Model\ResourceModel\Supplier\Collection"/>
<argument name="index" xsi:type="string">po_sup_id</argument>
<argument name="column_css_class" xsi:type="string">col-status</argument>
<argument name="header_css_class" xsi:type="string">col-status</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_manager">
<arguments>
<argument name="header" xsi:type="string" translate="true">Manager</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="options" model="Vendor\Module\Model\Order\Manager"/>
<argument name="index" xsi:type="string">po_manager</argument>
<argument name="column_css_class" xsi:type="string">col-status</argument>
<argument name="header_css_class" xsi:type="string">col-status</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_warehouse_id">
<arguments>
<argument name="header" xsi:type="string" translate="true">Warehouse</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="options" model="Vendor\Module\Model\Source\Warehouse"/>
<argument name="index" xsi:type="string">po_warehouse_id</argument>
<argument name="column_css_class" xsi:type="string">col-status</argument>
<argument name="header_css_class" xsi:type="string">col-status</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_eta">
<arguments>
<argument name="header" xsi:type="string" translate="true">ETA</argument>
<argument name="type" xsi:type="string">date</argument>
<argument name="index" xsi:type="string">po_eta</argument>
<argument name="escape" xsi:type="string">1</argument>
<argument name="column_css_class" xsi:type="string">col-name</argument>
<argument name="header_css_class" xsi:type="string">col-name</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_status">
<arguments>
<argument name="header" xsi:type="string" translate="true">Status</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="options" model="Vendor\Module\Model\Order\Status"/>
<argument name="index" xsi:type="string">po_status</argument>
<argument name="column_css_class" xsi:type="string">col-status</argument>
<argument name="header_css_class" xsi:type="string">col-status</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_delivery_progress">
<arguments>
<argument name="header" xsi:type="string" translate="true">Delivery progress</argument>
<argument name="type" xsi:type="string">number</argument>
<argument name="index" xsi:type="string">po_delivery_progress</argument>
<argument name="escape" xsi:type="string">1</argument>
<argument name="column_css_class" xsi:type="string">col-name</argument>
<argument name="header_css_class" xsi:type="string">col-name</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_grandtotal">
<arguments>
<argument name="header" xsi:type="string" translate="true">Grand total</argument>
<argument name="renderer" xsi:type="string">\Vendor\Module\Block\Order\Grid\Renderer\Total</argument>
<argument name="index" xsi:type="string">po_grandtotal</argument>
<argument name="escape" xsi:type="string">1</argument>
<argument name="column_css_class" xsi:type="string">col-name a-right</argument>
<argument name="header_css_class" xsi:type="string">col-name</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_invoice">
<arguments>
<argument name="header" xsi:type="string" translate="true">Invoices</argument>
<argument name="renderer" xsi:type="string">\Vendor\Module\Block\Order\Grid\Renderer\Invoice</argument>
<argument name="filter" xsi:type="string">\Vendor\Module\Block\Order\Grid\Filter\Invoice</argument>
<argument name="index" xsi:type="string">po_id</argument>
<argument name="sortable" xsi:type="string">false</argument>
<argument name="escape" xsi:type="string">1</argument>
<argument name="column_css_class" xsi:type="string">col-name a-right</argument>
<argument name="header_css_class" xsi:type="string">col-name</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_type">
<arguments>
<argument name="header" xsi:type="string" translate="true">Type</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="options" model="Vendor\Module\Model\Order\Type"/>
<argument name="index" xsi:type="string">po_type</argument>
<argument name="column_css_class" xsi:type="string">col-status</argument>
<argument name="header_css_class" xsi:type="string">col-status</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_shipping_tracking">
<arguments>
<argument name="header" xsi:type="string" translate="true">Tracking #</argument>
<argument name="type" xsi:type="string">text</argument>
<argument name="index" xsi:type="string">po_shipping_tracking</argument>
<argument name="escape" xsi:type="string">1</argument>
<argument name="column_css_class" xsi:type="string">col-name</argument>
<argument name="header_css_class" xsi:type="string">col-name</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_missing_price">
<arguments>
<argument name="header" xsi:type="string" translate="true">Missing prices</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="options" model="Vendor\Module\Model\Source\YesNo"/>
<argument name="index" xsi:type="string">po_missing_price</argument>
<argument name="column_css_class" xsi:type="string">col-status</argument>
<argument name="header_css_class" xsi:type="string">col-status</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="po_verified">
<arguments>
<argument name="header" xsi:type="string" translate="true">Verified</argument>
<argument name="type" xsi:type="string">options</argument>
<argument name="options" xsi:type="options" model="Vendor\Module\Model\Source\YesNo"/>
<argument name="index" xsi:type="string">po_verified</argument>
<argument name="column_css_class" xsi:type="string">col-status</argument>
<argument name="header_css_class" xsi:type="string">col-status</argument>
</arguments>
</block>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Massaction" name="adminhtml.indexer.grid.grid.massaction" as="grid.massaction">
<arguments>
<argument name="massaction_id_field" xsi:type="string">po_id</argument>
<argument name="form_field_name" xsi:type="string">entity_ids</argument>
<argument name="use_select_all" xsi:type="string">1</argument>
<argument name="options" xsi:type="array">
<item name="export" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Export</item>
<item name="url" xsi:type="string">*/*/massExport</item>
</item>
</argument>
</arguments>
</block>
</block>
</referenceBlock>
</body> </page>
Thanks!