3

How to pass dynamic value for <item name="componentDisabled" xsi:type="boolean">false</item> this component.

<?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">
    <columns name="sales_order_columns">
        <column name="order_comment">
            <argument name="data" xsi:type="array">
                <item name="js_config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
                </item>
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>                      
                    <item name="componentDisabled" xsi:type="boolean">false</item>
                    <item name="label" xsi:type="string" translate="true">Order Comment</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

I also refer http://devdocs.magento.com/guides/v2.2/ui_comp_guide/concepts/ui_comp_modifier_concept.html. But this only for admin form.

How to do this...Is there any possibility.....

7
  • You need to disable component? Feb 10, 2018 at 5:47
  • yes...@Suresh Chikani
    – Mahi M
    Feb 10, 2018 at 6:01
  • Based on above way, Its perfect way to disable component, Have you faced any issue related to above XML? Feb 10, 2018 at 6:16
  • the component is disable correctly.But i want to disable/enable this component dynamically from admin side- Enable Order_Comment Yes/no configuration
    – Mahi M
    Feb 10, 2018 at 6:20
  • @PriyaM Show your entire listing.xml file? Feb 10, 2018 at 6:40

1 Answer 1

1

Set Class as your classpath in column tag,

<?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">
    <columns name="sales_order_columns">
        <column name="order_comment" class="Mymodule\Modulename\Ui\Component\Listing\Columns\Comment">
            <argument name="data" xsi:type="array">
                <item name="js_config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
                </item>
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Order Comment</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

Create file at location, You need to pass your conditions

Under prepare() function

Create Commment.php Mymodule\Modulename\Ui\Component\Listing\Columns\Comment.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Mymodule\Modulename\Ui\Component\Listing\Columns;

use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Store\Model\StoreManagerInterface;


class Comment extends \Magento\Ui\Component\Listing\Columns\Column
{
    /**
     * Store manager
     *
     * @var StoreManagerInterface
     */
    protected $storeManager;

    /**
     * @param ContextInterface $context
     * @param UiComponentFactory $uiComponentFactory
     * @param StoreManagerInterface $storeManager
     * @param array $components
     * @param array $data
     */
    public function __construct(
        ContextInterface $context,
        UiComponentFactory $uiComponentFactory,
        StoreManagerInterface $storeManager,
        array $components = [],
        array $data = []
    ) {
        parent::__construct($context, $uiComponentFactory, $components, $data);
        $this->storeManager = $storeManager;
    }


    /**
     * Prepare component configuration
     * @return void
     */
    public function prepare()
    {
        parent::prepare();
        /* pass your conditions here in if  */
        if (YOUR_CONDITIONS) { 
            $this->_data['config']['componentDisabled'] = true;
        }
    }
}
7
  • if ($this->storeManager->isSingleStoreMode()) you need to pass your conditions here Feb 10, 2018 at 7:08
  • You have to keep your conditions instead of $this->storeManager->isSingleStoreMode() in if statement Feb 10, 2018 at 8:29
  • Try with this, public function prepare() { parent::prepare(); /* pass your conditions here in if */ $helper = \Magento\Framework\App\ObjectManager::getInstance()->get('Xxx\OrderComment\Helper\Data'); if (!$helper->isEnable()) { $this->_data['config']['componentDisabled'] = true; }} Feb 10, 2018 at 8:42
  • still showing....
    – Mahi M
    Feb 10, 2018 at 8:49
  • try to check by print object using $this->_data['config'] any value is getting or not. Feb 10, 2018 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.