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
Module Initialization
Registration File
Create registration.php file in the root folder. This file is the starting point of our module
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.
Running Setup Upgrade
Run the following command to initialize and install the module.
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
ACL Configuration
Create acl.xml file inside “etc/acl.xml which will be used to define access control for the module.
Creating Backend Controller
Routes Configuration
Create the routes.xml file in “etc/adminhtml”. This defines the URL path for the module
Controller File
Create a controller file inside “Controller\Adminhtml\Custom” name the file as CustomDataProvider.php. This defines the action for the route
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”
UI Component Configuration
The ui_component file configures the UI component, create a grids_custom_customdataprovider_list.xml inside view\adminhtml\ui_component
Custom Data Provider
Data Provider Class
The custom data provider class fetches and processes the data .Create custom.php inside “Ui\Component\DataProvider”
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?
Would you like to share this article?
All Categories
Latest Post
- Magento 2 Rich Text Schema Setup in JSON-LD: Step-by-Step Guide
- Fixing Magento 2 Product Schema Markup | Missing “image” field FIX
- How to Dispatch Custom Events in Magento 2
- Adding Filters in Magento Admin Grid | Column and Non-Column Component
- How to add custom styles (Colors and Fonts) to Magento Admin Grid