2

So I'm creating an admin grid and one of the fields is a dropdown select:

<?php

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

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

    public function toOptionArray()
    {
        // return your data
        return [['value' => 0, 'label' => __('Option 1')], ['value' => 0, 'label' => __('Option 2')]];
    }
}

I noticed that you can just pass a label and value without calling a status table, I initially created one with my module because I thought of usual DB design of using foreign keys to match it to a value in an options table, but this function toOptionArray makes that seem redundant.

So my question is, do I need those FK tables or is this enough?

Thanks!

1 Answer 1

0

It depends on what you need to do. Technically, the grid and form can function with hard coded values for dropdowns, but if you have dynamic values you need to use for sure a source model for them.

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.