I needed a custom column to be displayed in order Grid (Yes/No) Type. So I followed below steps:
I created a new column in table "sales_order_grid"
$installer->getConnection()->addColumn( $setup->getTable('sales_order_grid'), 'is_prebook', [ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, 'length' => 11, 'default' => '0', 'nullable' => true, 'comment' => 'Prebook' ] );
- Then created sales_order_grid.xml app/code/Akhil/Prebook/view/adminhtml/ui_component/sales_order_grid.xml
<?xml version="1.0"?> <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> <columns name="sales_order_columns"> <column name="is_prebook"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="visible" xsi:type="boolean">true</item> <item name="label" xsi:type="string" translate="true">Prebook</item> </item> </argument> </column> </columns> </listing>
Column added successfully but value showing '0' How to display as 1=>Yes & 0=> No
Tried below code. Is this should make sense here?
<item name="dataType" xsi:type="string">select</item>
<item name="options" xsi:type="object">Akhil\Prebook\Model\Source\Prebookstatus</item>
File: Akhil\Prebook\Model\Source\Prebookstatus
class Prebookstatus implements \Magento\Framework\Option\ArrayInterface {
/**
* Retrieve status options array.
*
* @return array
*/
public function toOptionArray() {
return [
['value' => 0, 'label' => __('No')],
['value' => 1, 'label' => __('Yes')]
];
}
}