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 name="label" xsi:type="string" translate="true">Sync Status</item>

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"


1 Answer 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';
                case 2:
                    $class = 'major';
                    $value = 'Sync. Error';
                case 0:
                    $class = 'minor';
                    $value = 'Sync. Pending';
                case 1:
                    $class = 'notice';
                    $value = 'Sync. Success';
            $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 and acknowledge you have read our privacy policy.

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