Skip to main content
deleted 371 characters in body
Source Link
Herve Tribouilloy
  • 7.8k
  • 2
  • 14
  • 28
    class OrderStatusRenderer extends \Magento\Ui\Component\Listing\Columns\Column
    {
        /**
         * Prepare Data Source
         *
         * @param array $dataSource
         * @return array
         */
        public function prepareDataSource(array $dataSource)
        {
            if (isset($dataSource['data']['items'])) {
                foreach ($dataSource['data']['items'] as & $item) {
                    if ($this->getData('name') === 'status') {
                    switch    if ($item[$this->getData('name')]) {
                        case== 'complete':
                            $color = 'red';
                            break;
                        case) 'pending':{
                            $color$result = 'green';
                            break;'Yes';
                       } caseelse 'processing':{
                            $color$result = 'orange';'No';
                            break;}
                        default:
                            $color$item[$this->getData('name')] = 'grey';$result;
                    }
 
                    $item[$this->getData('name')] = sprintf('color:%s  label:%s', $color, $item[$this->getData('name')]);}
                }
        
     }
       return }
$dataSource;
        return $dataSource;}
    }
}

hopefully, these infos answer your question

class OrderStatusRenderer extends \Magento\Ui\Component\Listing\Columns\Column
{
    /**
     * Prepare Data Source
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                if ($this->getData('name') === 'status') {
                    switch ($item[$this->getData('name')]) {
                        case 'complete':
                            $color = 'red';
                            break;
                        case 'pending':
                            $color = 'green';
                            break;
                        case 'processing':
                            $color = 'orange';
                            break;
                        default:
                            $color = 'grey';
                    }
 
                    $item[$this->getData('name')] = sprintf('color:%s  label:%s', $color, $item[$this->getData('name')]);
                }
            }
        }

        return $dataSource;
    }
}
    class OrderStatusRenderer extends \Magento\Ui\Component\Listing\Columns\Column
    {
        /**
         * Prepare Data Source
         *
         * @param array $dataSource
         * @return array
         */
        public function prepareDataSource(array $dataSource)
        {
            if (isset($dataSource['data']['items'])) {
                foreach ($dataSource['data']['items'] as & $item) {
                    if ($this->getData('name') === 'status') {
                        if ($item[$this->getData('name')] == 'complete') {
  $result = 'Yes';
} else {
  $result = 'No';
}
    
                        $item[$this->getData('name')] = $result;
                    }
                }
            }
     
            return $dataSource;
        }
    }

hopefully, these infos answer your question

Source Link
Herve Tribouilloy
  • 7.8k
  • 2
  • 14
  • 28

It is quite simple and the reason is that you don't need any new data to make the job. you may create a custom module in app/code/Vendor/OrderGrid .. (see screenshot of my module enter image description here

mine was Mbs/OrderGrid) In the file sales_order_grid.xml you can define your column

select select Required

the class Mbs\OrderGrid\Ui\Component\Listing\Column\OrderStatusRenderer is what you need to get right:

class OrderStatusRenderer extends \Magento\Ui\Component\Listing\Columns\Column
{
    /**
     * Prepare Data Source
     *
     * @param array $dataSource
     * @return array
     */
    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                if ($this->getData('name') === 'status') {
                    switch ($item[$this->getData('name')]) {
                        case 'complete':
                            $color = 'red';
                            break;
                        case 'pending':
                            $color = 'green';
                            break;
                        case 'processing':
                            $color = 'orange';
                            break;
                        default:
                            $color = 'grey';
                    }

                    $item[$this->getData('name')] = sprintf('color:%s  label:%s', $color, $item[$this->getData('name')]);
                }
            }
        }

        return $dataSource;
    }
}