How to Create Custom Admin Grid

Blog
Spread the love

In this blog we will learn how to create custom admin grid. Magento 2 grids are a way to list the items in a database table for better management. Grid allows us to sort, filter, edit and update data.

Before you begin: You should have a custom module, in that you need to create menu and other related files and folders.

If you want to create custom menu click here.

To register a frontend route, we must create a routes.xml file:

Step 1: Create routes.xml

app/code/Bluethink/CustomMenu/etc/adminhtml/routes.xml

The id attribute is a unique string which will identify this route.

The frontName attribute is also a unique string which will be shown on the url request.

Step 2: Create controller

app/code/Bluethink/CustomMenu/Controller/Adminhtml/Post/Index.php

All controllers have to contain a public execute method. It is called when accessing the controller. The storefront controllers are inherited from the \Magento\Framework\App\Action\Action class.

After create controller we will create layout file.

Step 3: Create menu_post_index.xml

app/code/Bluethink/CustomMenu/view/adminhtml/layout/menu_post_index.xml

The layout file is an XML file which will define the page structure.

In this layout file, we declare an uiComponent for the content of this page. Basically with uiComponent, Magento allows us to create nice user interface for lists, forms etc. we need to create ui_component folder inside view/adminhtml folder.

Step 4: Create quote_listing.xml

app/code/Bluethink/CustomMenu/view/adminhtml/ui_component/quote_listing.xml

In the ui_component folder, we will finally create the UI Grid and display customer data.

Step 5: Create di.xml

app/code/Bluethink/CustomMenu/etc/di.xml

Declare resource in dependency injection file. Now we will create di.xml file which will connect to the Model to get the data for our grid.

The type is used for changing arguments of class or to pass new arguments to that class. Whereas virtualType is used to create a virtual sub-class (means we don’t have to create the .php file).

Step 6: Create UpgradeSchema.php

app/code/Bluethink/CustomMenu/Setup/UpgradeSchema.php

In this blog we use magento quote table, we need to index table for perform full text search in admin grid.

Step 7: Run command

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento cache:flush

Magento 2

You can download sample module for admin menu here.

bluethinkinc_blog

bluethinkinc_blog

2022-09-01

0

Leave a Reply

Your email address will not be published. Required fields are marked *

Find More Blogs

Exception Handling in Java

Spread the love Introduction – Exception:An unwanted

How to add custom less file in Magento2

Spread the love Source files *.css included into layout

Spring Boot Microservices

Spread the love Microservices architecture has become

Implementation of WireMock for better testing

Spread the love WireMock is a flexible and powerful tool

Magento 2: How to selected default option in configurable options?

Spread the love Configurable products in Magento 2 allow

How To Implement Simple JWT Authentication in Django Rest Framework

Spread the love We’ll learn how to use simple JWT

Optimizing Search: Integrating Elasticsearch in Django Applications

Spread the love What is Elasticsearch? Elasticsearch is a

How to create Customer Segments

Spread the love In Magento 2, “customer

Proxy Design Pattern and Requisition List in Magento 2

Spread the love Requisition List in Magento 2 Requisition

Google Ads Conversion Tracking Through Magento Platform:

Spread the love Google Ads Conversion Tracking Through

bluethinkinc Blogs