Magento 2 is an eCommerce framework. Magento 2 divided into two editions community edition and enterprise edition. Sometimes, developer-facing issues on backend Magento provides many featured for Magento developers. Like Theme integration, Extension development, Data Migration, product import-export.
In this blog, We will discuss on how to create custom grid on admin panel. Before we start, First we need to create a custom extension. also, Need to define a custom table.
Let's Start!!!
Module Name: StudentManagement
Company Name: TryCoder
Database TableName: studentinfo
Database Table FieldName:
- id
- student_name
- student_class
- mobile_no
- student_info
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
</config>
module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="TryCoder_StudentManagement" setup_version="1.0.0">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Sales"/>
<module name="Magento_Quote"/>
<module name="Magento_Checkout"/>
<module name="Magento_Cms"/>
</sequence>
</module>
</config>
Create "Setup" folder inside the module and add below file:
InstallSchema.php
<?php
namespace TryCoder\StudentManagement\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\DB\Adapter\AdapterInterface;
class InstallSchema implements InstallSchemaInterface
{
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.0') < 0){
$installer->run('create table studentinfo(id int not null auto_increment, student_name varchar(100), student_class varchar(100), mobile_no varchar(100), student_info text(100), primary key(id))');
}
$installer->endSetup();
}
}
Under Module Root Dir add below two file:
composer.json:
{
"name": "trycoder/studentmanagement",
"description": "TryCoder StudentManagement",
"require": {
"php": "~5.6.0|7.0.2|~7.0.6",
"magento/module-store": "0.74.0-beta4",
"magento/module-theme": "0.74.0-beta4",
"magento/module-widget": "0.74.0-beta4",
"magento/module-backend": "0.74.0-beta4",
"magento/module-catalog": "0.74.0-beta4",
"magento/module-email": "0.74.0-beta4",
"magento/module-ui": "0.74.0-beta4",
"magento/module-variable": "0.74.0-beta4",
"magento/module-media-storage": "0.74.0-beta4",
"magento/framework": "0.74.0-beta4",
"magento/magento-composer-installer": "*"
},
"type": "magento2-module",
"version": "0.74.0-beta4",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"extra": {
"map": [
[
"*",
"TryCoder/StudentManagement"
]
]
}
}
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'TryCoder_StudentManagement',
__DIR__
);
After added above all files, We need to run below command and enable module in our projects.
- php bin/magento c:c
- php bin/magento deploy:mode:set development
- php bin/magento s:up
- php bin/magento s:d:c
- php bin/magento s:s:d -f
- php bin/magento c:c
Then, Give folder permission if required and check module on app/etc/config.php
Now, I am writing coding related module grid creating. We can create adminpanel grid below using two ways.
- Create grid using UI components
- Create grid using Block Class
Comments
Post a Comment
Please do not enter any spam link in the comment box.