Skip to content

how to add dynamic options for records by select column in uicomComponent grid

I don’t want all records to use the same options and I want each record in the grid to have different options in the column select
and and I do the following I have class TimeUseActions

<?php
/**
 * TimeUseActions
 *
 * @copyright
 * @author   
 */

namespace DbizVoucherUIComponentVoucherModalColumn;

use MagentoFrameworkDataOptionSourceInterface;
use MagentoFrameworkViewElementUiComponentContextInterface;
use MagentoFrameworkViewElementUiComponentFactory;
use MagentoUiComponentListingColumnsColumn;

class TimeUseActions extends Column // implements OptionSourceInterface
{
    protected $timeOptions;
    protected array $customOptions = [['value' => 'init',
        'label' => ' Init Custom Label for ID ']];

    public function __construct(
        ContextInterface   $context,
        UiComponentFactory $uiComponentFactory,
        TimeOptions        $timeOptions,
        array              $components = [],
        array              $data = []
    ) {
        parent::__construct($context, $uiComponentFactory, $components, $data);
        $this->timeOptions = $timeOptions;
    }

    public function prepareDataSource(array $dataSource): array
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as &$item) {
                if (isset($item['entity_id'])) {
                    $item['time_use'] =[ ['label' => __('label 1 '), 'value' => '1'], ['label' => __('label 1 '), 'value' => '1']];
                    $item['time_use_option'] = [['label' => __('label 1 '), 'value' => '1']];
                    $item['service'] = 'hello';
                }
            }
        }
        return $dataSource;
    }
   
}

it provides data for column

<column name="time_use_option" class="DbizVoucherUIComponentVoucherModalColumnTimeUseActions"  sortOrder="120" >
        <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">select</item>
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                <item name="editor" xsi:type="string">select</item>
                <item name="dataType" xsi:type="string">select</item>
                <item name="label" xsi:type="string" translate="true">Time Option</item>
                <item name="visible" xsi:type="boolean">true</item>
            </item>
        </argument>
    </column>

why it doesn’t work