Magento2: Add column sale grid

The following code will demonstrate how one can add last order updated date (updated_at) in sales order grid.This column is most useful one while order processing.

We will achieve above result in two steps.

  1. Creating bare minimum extension.
  2. using ui_component

1. Creating Extension :
A bare minimum extension can be created using online tools such as “silksoftware.com” or “mage2gen.com” website.

2. Using UI_Component
One has to override base code (XML) to add a new column.
Lets create “sales_order_grid.xml” file in following location. File name is importent as it must match code structure.

[company]/[module]/view/adminhtml/ui_component/sales_order_grid.xml

One can look into core code to use for reference.

[root]/vendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml

	<listing xmlns:xsi="http://www.......xsd">
<columns>
<column name="updated_at" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">dateRange</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="dataType" xsi:type="string">date</item>
<item name="label" xsi:type="string" translate="true">Updated Date</item>
<item name="dateFormat" xsi:type="string">MMM dd, YYYY, H:mm:ss A</item>
</item>
</argument>
</column>
</columns>
</listing>

Thats it Enable the extension and clean the cache.

updated_at

You can find code on GitHub

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s