2

How to change the grid column value basend on the certain value in another column of that record (row).

I have two column step1_formula and step2_formula if user selected step2 formula from UI form i need to show the content of both column in grid but if user select only step1_formula I need to show Not Applicable in the column step2_formula on that record (row )

1
  • You can display different amount of rows per page in Magento Dashboard. Is this applied to rows on the current page or all rows?
    – MTP
    Commented Oct 5, 2022 at 8:31

1 Answer 1

2

you can show hide ui component grid column by this way in ui component.

Add a custom class in your column

    <column name="step1_formula" class="vendor\module\Ui\Component\Listing\Column\FormulaGridActions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true"> Step1 Formula </item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>
                        </item>
                    </item>
                </item>
            </argument>
        </column>

Paste the following code here

vendor\module\Ui\Component\Listing\Column\FormulaGridActions

<?php

namespace vendor\Module\Ui\Component\Listing\Column;

use Magento\Framework\Exception\LocalizedException;
use Magento\Ui\Component\Listing\Columns\Column;


class FormulaGridActions extends Column
{
    public function __construct(
        \Magento\Framework\View\Element\UiComponent\ContextInterface $context,
        \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory,
        array $components = [],
        array $data = []
    ){
        parent::__construct($context, $uiComponentFactory, $components, $data);
    }


    public function prepareDataSource(array $dataSource) {
        if (isset($dataSource['data']['items'])) {

            foreach ($dataSource['data']['items'] as & $item) {

                if($item['result_steps'] == 0)
                {
                    $item['step2_formula'] = ""; 
                    // $item['step1_formula'] = $item['result_color_grams'].''.; 
                }

            }
        }

        return $dataSource;
    }

 */
    public function prepare()
    {
       if ($condition) { // Your condition goes here
       $status = true;
        }
          $this->_data['config']['componentDisabled'] = true; // for removing the column
          parent::prepare();
    }


}

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.