0

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 Dbiz\Voucher\UI\Component\VoucherModal\Column;

use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;

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="Dbiz\Voucher\UI\Component\VoucherModal\Column\TimeUseActions"  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

1 Answer 1

0

I think your XML is OK:

<column name="time_use_option" sortOrder="120" >
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Dbiz\Voucher\UI\Component\VoucherModal\Column\TimeUseActions</item>
        <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>

But your controller should implement from Magento\Framework\Option\ArrayInterface because you're doing a Select.

The class Magento\Ui\Component\Listing\Columns\Column is more commonly used (for example) for the action buttons.

Hope this works for you.

2
  • Thanks for answering Because I want each record in the grid to have different options in the column select, I just implemented class Magento\Ui\Component\Listing\Columns\Column
    – Abu Shino
    Feb 5 at 8:17
  • I don't want all records to use the same options
    – Abu Shino
    Feb 5 at 8:18

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.