In the USA, tax rates vary widely among most states and some localities. In order to add tax rates for different cities, some of our clients had a pressing need to add a city column to the ‘Tax Manager’ admin grid. To solve this, we were working on developing an extension in Magento 2. But adding the column was not a straight-forward affair. We faced some challenges in overriding the admin grid in Magento 2. We resolved this and as usual, wanted to share our solution so that the community benefits as well.

Step by step procedure : Magento 2 – How to Add a New Column in Admin Grid?

Step 1:

Module Registration

Create a custom module based on the Magento 2 structure in the folder app/code

File Path : Magento-CE-2.0.8/app/code/DCKAP/Tax/registration.php

Step 2:

Module Configuration

Create a module.xml file in the below path to define your Magento 2 extension

File Path: Magento-CE-2.0.8/app/code/DCKAP/Tax/etc/module.xml

Step 3:

Override Grid
Locate the core module admin grid xml file path. Create the same folder path under custom module.

File Path :  Magento-CE-2.0.8/app/code/DCKAP/Tax/view/adminhtml/layout/tax_rate_block.xml

Step 4:

Create custom field
Create a new field ‘City’ and define this under the reference block it needs to be shown.

After completing the above steps run the below command.

After running the above command, clear all the Magento cache and check if the extension has been successfully installed in Magento 2 admin.

Once the extension has been installed you will be able to view the custom field in admin as shown in the screen shot below.

add column magento 2

 

Hope the blog was useful. Let us know if you have any comments or queries. We will be happy to hear from you.

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.

Tags

READY TO DRIVE SALES?

Request a Quote Today

Request a Quote

Leave a Reply

7 Comments on "Magento 2 – How to Add a New Column in Admin Grid?"


Guest
Mohit
4 months 4 days ago

Hi Thanga Durai,
Thanks for the nice post. I have a question.

I am using renderer in the custom column. Now I want to filter column values by the values rendered by the renderer class, but it is filtering column values based on the original values.

Can you help me ?

Guest
Vishal S
9 months 23 days ago

Hi Thanga,

Really Nice post. Perfect!!
Could you please let me know how can we add new column with custom data in the “Order Export CSV”?
Thanks

Guest
wisam hakim
10 months 24 days ago

Thank you for this fantastic information,
But you did not write how we can add the field to the form and also how to add the column to the Database,
in this way we only display the field on the grid, could you please help me?

Guest
vivek
1 year 2 months ago

how to create custom new input field in sales order in admin

Thanga Durai
Author
1 year 2 months ago

Hi Vivek,
Thanks for your query. We need some information from our end.
Where do you want to add custom input field in Sales Order Admin…
1. Sales Order Admin Grid
2. Sales Order View (e.g. Comments)
3. Order Creation through Admin
Please let us know. It will help us to answer your query.
Please subscribe to our blogs.
Thanks.

Guest
Mohamed Ibrahim
1 year 5 months ago

Hi Thanga Durai,

How to use this way to add tracking number in the order sales grid?

Thank you

Thanga Durai
Author
1 year 5 months ago

Hi Ibrahim,

Thanks for your patience…he is the answer…

You need to override the UI component sales_order_grid.xml under [NAMESPACE]/[MODULE]/view/adminhtml/ui_component/sales_order_grid.xml

Like Below:

true
New Filed Name

Then you need to create the UI class under [NAMESPACE]/[MODULE]/Ui/Component/Listing/Column/Datas.php and write data which is you want.

Please let me know if you have any queries.
Subscribe to our blogs for more such interesting articles.
Thanks.