Customizing Magento 2 Admin Grid Using UI Components and Data Providers
ecommerce Magento Technical

Customizing Magento 2 Admin Grid Using UI Components and Data Providers

In this series of tutorials, we will be discussing how to customize Magento 2 admin grids using UI components. We will cover some conventional and non-conventional techniques to achieve these customizations.

In this first tutorial, we will focus on using a custom data provider to pass custom data to the admin grid. Let’s get started.

Full Video Walkthrough by CodeWithAli

Setting Up the Environment

Official Magento UI Component Documentation

Before diving into the customization, it’s crucial to refer to the official UI component documentation of Magento. This resource is invaluable when customizing UI components.

Magento 2.4.7 Setup

For this tutorial author has used standard Magento 2.4.7 copy set up using the Mark Shust’s Magento Docker repository, which will be used throughout the series.

Creating the Basic Module

Our first task is to create a basic module named Demo_AdminGrids that we will use throughout the series.

Module Initialization

Registration File

Create registration.php file in the root folder. This file is the starting point of our module

Click here to view and edit & add your code between the textarea tags

Module Configuration File

Create an etc. folder inside the root and create a new module.xml inside this folder, this file defines the module and its dependencies. 

Click here to view and edit & add your code between the textarea tags

Running Setup Upgrade

Run the following command to initialize and install the module.

Click here to view and edit & add your code between the textarea tags

Configuring the Module

Adding Menu and ACL

Menu Configuration

To create a menu item in the admin pane, create the menu.xml fine inside etc/adminhtml

Click here to view and edit & add your code between the textarea tags

ACL Configuration

Create acl.xml file inside “etc/acl.xml which will be used to define access control for the module.

Click here to view and edit & add your code between the textarea tags

Creating Backend Controller

Routes Configuration

Create the routes.xml file in “etc/adminhtml”. This defines the URL path for the module

Click here to view and edit & add your code between the textarea tags

Controller File

Create a controller file inside “Controller\Adminhtml\Custom” name the file as CustomDataProvider.php. This defines the action for the route

Click here to view and edit & add your code between the textarea tags

Creating UI Component

Layout Configuration

Layout File

The layout file defines the structure of the page. Create a grids_custom_customdataprovider.xml file inside “view\adminhtml\layout”

Click here to view and edit & add your code between the textarea tags

UI Component Configuration

The ui_component file configures the UI component, create a grids_custom_customdataprovider_list.xml  inside view\adminhtml\ui_component

Click here to view and edit & add your code between the textarea tags

Custom Data Provider

Data Provider Class

The custom data provider class fetches and processes the data .Create custom.php inside Ui\Component\DataProvider”

Click here to view and edit & add your code between the textarea tags

In this tutorial, we created a basic Magento 2 module and configured it to use a custom data provider for an admin grid. We covered the essential files and configurations needed to get a custom admin grid up and running. Stay tuned for the next tutorial where we will dive deeper into customizing the filters and data processing in the grid.

Would you like to integrate Whatsapp or APIs into your website or mobile app?