0

I have a select box in filter section of admin grid. I need to set default selected option. Here is my code

Model/Config/Source/Errortype.php

<?php
namespace Bridge\ErrorNotification\Model\Config\Source;

use Magento\Framework\Option\ArrayInterface;

class Errortype implements ArrayInterface
{
  public function toOptionArray()
  {
    $result = [];
    foreach ($this->getOptions() as $value => $label) {
        $result[] = [
             'value' => $value,
             'label' => $label,
         ];
    }

    return $result;
  }

  public function getOptions()
  {
    return [
        'select' => __('Select'),
        '404' => __('404'),
        'System Error' => __('System Error'),
        'Login Failed' => __('Login Failed'),
    ];
  }
 }

view/adminhtml/ui_componenet/listing.xml

    <column name="error_type" component="Magento_Ui/js/grid/columns/select">
        <settings>
            <label translate="true">Error Type</label>
            <options class="Bridge\ErrorNotification\Model\Config\Source\Errortype"/>
            <filter>select</filter>
            <dataType>select</dataType>
        </settings>

    </column>

1 Answer 1

0

Please check below code, i hope it will work.

view/adminhtml/ui_componenet/listing.xml

<column name="error_type" component="Magento_Ui/js/grid/columns/select">
    <settings>
        <label translate="true">Error Type</label>
        <options class="Bridge\ErrorNotification\Model\Config\Source\Errortype"/>
        <caption translate="true">Your default option</caption>
        <filter>select</filter>
        <dataType>select</dataType>
    </settings>
</column>
1
  • caption is not showing in select box Jun 4, 2020 at 6:30

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.