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

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

Object Pool Pattern in Magento2

Spread the love What is Object Pool Pattern in Magento 2 An

JENKINS

Spread the love JENKINS Introduction and Installation

Virtual Type and Type

Spread the love Virtual type is one of the most common

Customize the length of Input field

Spread the love Sometimes we need to change the limit the

How to Add Custom Tab on Admin Dashboard and Count Website Total Visitor in Magento 2?

Spread the love In this blog we’ll see How to Add Custom

How to Add Sign Out Tab in Customer Account in Magento 2?

Spread the love In this blog we’ll see How to Add

How to create custom tab in product detail page in magento 2?

Spread the love In this blog we’ll see how to add

Understanding and Implementing CORS & CSRF

Spread the love What is security? The world has become more

bluethinkinc Blogs