4

I'm using magento v2.2.5 and i created a column with inline edit like this:

xml ui component

 <column name="enabled">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="label" translate="true" xsi:type="string">Enabled</item>
                <item name="editor" xsi:type="string">select</item>
                <item name="options" xsi:type="object">Namespace\Module\Model\Source\EnabledOptions</item>
            </item>
        </argument>
    </column>

Namespace\Module\Model\Source\EnabledOptions

namespace Namespace\Module\Model\Source;

class EnabledOptions implements \Magento\Framework\Option\ArrayInterface
{

    public function toOptionArray()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }

    public static function getOptionArray()
    {
        $options['yes'] = __("Yes");
        $options['no'] = __("No");
        return $options;
    }

    public function getAllOptions()
    {
        $result = [];

        foreach (self::getOptionArray() as $index => $value) {
            $result[] = ['value' => $index, 'label' => $value];
        }

        return $result;
    }


    public function getOptionText($optionId)
    {
        $options = self::getOptionArray();

        return isset($options[$optionId]) ? $options[$optionId] : null;
    }
}

but i got an empty options like this:

enter image description here

edit:

after i inspected the browser console, there is an error like this:

enter image description here

0

Try to use below code

<column name="enabled">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Namespace\Module\Model\Source\EnabledOptions</item>
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">select</item>
                    <item name="label" xsi:type="string" translate="true">Enabled</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                    <item name="dataType" xsi:type="string">select</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">select</item>
                    </item>
                </item>
            </argument>
        </column>
  • is that code working @Shell Suite ? – Ansar Husain Aug 28 '18 at 10:20
  • 1
    not working, it makes my table column record empty too – Shell Suite Aug 28 '18 at 10:28
  • @AnsarHusain have you found a solution? I am having this issue too – Juliano Vargas Apr 2 at 13:29
0

I've found a solution for this please bellow what works for me all I was missing was template:

<column name="status">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Yesno</item>
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="sortOrder" xsi:type="number">10</item>
                    <item name="label" xsi:type="string" translate="true">Active</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                    <item name="template" xsi:type="string">ui/grid/filters/elements/ui-select</item>
                    <item name="dataType" xsi:type="string">select</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">select</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>
                        </item>
                    </item>
                </item>
            </argument>
        </column>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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