In this article, we will discuss how to utilize the action of a grid backend Magento 2 with custom code by the following steps:
Have a good online marketplace idea? Get Your Free Consultation Get your free Multi-vendor marketplace platform demo: Click here Build your marketplace business at just $99 with a robust extension
Step 1: Form a grid, Magento 2
Step 2: Set ID for this grid
Step 3: Form a template file with a URL
Step 4: Find grid object name of the grid
Step 5: Form a JavaScript object
Step 6: Make use of some function
In the previous post, we learn about the Magento 2 backend inline editing grid code. In this post, we will utilize Magento 2’s function in a grid backend with custom code. In Magento 1, it is very easy to form a grid to show data in the backend and is very comparable to Magento 2.
Utilize Action of a Grid Backend Magento 2
With one module, you can form a stage to easily display data on the data. However, Magento 2 gives you two ways to create a grid in the backend. Today, I will help you to utilize the Magento 2 Action in a Grid Backend in the Simple Code of Simple way:
Step 1: Form a grid, Magento 2
I formed a grid in Magento 2 like this.
app\code\My_Vendor\My_Module_Name\Block\Adminhtml\Product\Grid
Step 2: Set ID for this grid
In this grid, I set ID for this grid in the _construct function.
protected function _construct() { parent::_construct(); $this->setId("list_products"); $this->setDefaultSort("entity_id"); $this->setUseAjax(true); }
Step 3: Form a template file with a URL
I form a template file with a URL
app\code\My_Vendor\My_Module_Name\view\adminhtml\templates\product\grid.phtml
Step 4: Find grid object name of the grid
In this template, I find the grid object name of the grid
$gridJsObjectName = $blockGrid->getJsObjectName();
Step 5: Form a JavaScript object
I form a javascript object from $gridJsObjectName
var gridJsObject = window[‘<?php echo $gridJsObjectName ?>’],
Step 6: Make use of some function
By this JavaScript object, you can exploit some functions like a filter, reset filter, etc
gridJsObject .doFilter(); gridJsObject .reload();
These 6 steps explain to you how to utilize Action of a Grid Backend Magento 2 with Custom Code. Hope all of you guys can learn Magento 2 more easily with our tutorial.
Leave a Reply