0

I am using an ui_component (listing) for a custom grid in magento 2.2. I have a status colum with various value, see below:

enter image description here

Here is the column declaration in the "listing" component

 <column name="status">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</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 name="label" xsi:type="string" translate="true">Sync Status</item>
            </item>
        </argument>                     
    </column>

How can I associate the integer value to text value.

0=> pending 1=> synced

I know how to do it in a classic grid but I can make it work with the "listing"

regards

1

So I actually Created a Status.php file in the folder [MyModule]/Ui/Component/Listing/Column

With the following function :

public function prepareDataSource(array $dataSource)
{

    if (isset($dataSource['data']['items'])) {
        foreach ($dataSource['data']['items'] as & $item) {
            switch ($item['status']) {
                case 3:
                    $class = 'critical';
                    $value = 'Sync. Exception';
                    break;
                case 2:
                    $class = 'major';
                    $value = 'Sync. Error';
                    break;
                case 0:
                    $class = 'minor';
                    $value = 'Sync. Pending';
                    break;
                case 1:
                    $class = 'notice';
                    $value = 'Sync. Success';
                    break;
            }
            $item['status'] = '<span class="grid-severity-' . $class . '">' . $value . '</span>';
        }
    }

    return $dataSource;
}

So now I have a fancy column style using a built-in css class:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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