Skip to main content
3 of 8
update question
Purushotam Sharma
  • 1.7k
  • 2
  • 26
  • 60

Magento 2: how to get the product attribute option label instead of option value in admin grid in custom module?

I want to show product attribute option label instead of option value in admin grid in custom module?

Can any one help me in this?

In magento 1 I get this suggestion and same I want in magento 2.

below is the file that show static status in admin grid and I want to retrieve product attribute options and values in admin grid:-

namespace Company\Module\Model;
    
    class Probore
    {
        /**#@+
         * Module Probore values
         */
        const STATUS_NEW = 1;    
        const STATUS_PROCESSING = 2;        
        const STATUS_COMPLETED = 3;
    
        /**
         * Retrieve option array
         *
         * @return string[]
         */
        public static function getOptionArray()
        {
            return [self::STATUS_NEW => __('New'),
                self::STATUS_PROCESSING => __('Processing'),
                self::STATUS_COMPLETED => __('Completed')];
        }
    
        /**
         * Retrieve option array with empty value
         *
         * @return string[]
         */
        public function getAllOptions()
        {
            $result = [];
    
            foreach (self::getOptionArray() as $index => $value) {
                $result[] = ['value' => $index, 'label' => $value];
            }
    
            return $result;
        }
    
        /**
         * Retrieve option text by option value
         *
         * @param string $optionId
         * @return string
         */
        public function getOptionText($optionId)
        {
            $options = self::getOptionArray();
    
            return isset($options[$optionId]) ? $options[$optionId] : null;
        }
    }

How to retrieve attribute and assign in the admin grid so option label is visible in admin grid.

Purushotam Sharma
  • 1.7k
  • 2
  • 26
  • 60