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?
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
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
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
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.
Hope the blog was useful. Let us know if you have any comments or queries. We will be happy to hear from you.