I need to add a drop down in the admin grid of a custom module. I have set the editor type as select, but how to set the data source of the select to read from another database table?

I need to populate the select with data coming as result of SQL query.

enter image description here

enter image description here

  • 1
    Let me know if you have any issue Aug 30, 2017 at 9:57

1 Answer 1


Add select options and component in column. Full column like this:

<column name="items">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">{Vendor}\{Module}\Ui\Component\Listing\Column\Myoptions</item>
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">select</item>
            <item name="label" xsi:type="string" translate="true">Items</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 name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>

Now create Myoptions.php at


Now you can load table and pass array data in toOptionArray() like


namespace Vendor\Module\Ui\Component\Listing\Column;

class Status implements \Magento\Framework\Option\ArrayInterface
    //Here you can __construct Model

    public function toOptionArray()
        return [
            ['value' => 0, 'label' => __('Option 1')],
            ['value' => 1, 'label' => __('Option 2')]
  • Happy to help, Happy Coding...:) Aug 30, 2017 at 10:21
  • one more thing , how to pass parameters to Myoptions.php? i need to pass the row entity_id to select items related to that record only
    – Zorox
    Aug 30, 2017 at 10:22
  • while exporting csv file . I am getting only values but i want label there in csv file ,
    – mohan
    Sep 24, 2018 at 7:21
  • @PrincePatel it helped me to display the status values in the filter but it doesn't render the drop-down within the grid cell. Magento 2.2.5
    – Adnan
    Nov 3, 2018 at 2:15
  • @PrincePatel Very well explained answer +1 for that. Sep 19, 2019 at 7:02

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.