Skip to main content

Magento 2 custom module grid not showing

 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: 

  1. id
  2. student_name
  3. student_class
  4. mobile_no
  5. student_info
Module Path:  app/code/TryCoder/StudentManagement

Create "etc" folder inside the module and add below files:

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.

  1. php bin/magento c:c
  2. php bin/magento deploy:mode:set development
  3. php bin/magento s:up
  4. php bin/magento s:d:c
  5. php bin/magento s:s:d -f
  6. 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.

  1. Create grid using UI components
  2. Create grid using Block Class
Before we start discussion let me add dummy data on "studentinfo" table using phpmyadmin.
Let's discuss on step by step

1. Create Grid By UI components



Comments

Popular posts from this blog

JavaScript Functions

  Hi there, and welcome to another exciting lesson on JavaScript. If this is your first time here, please do well to check out our previous lessons. In the previous lesson, we were discussing JavaScript math methods. It was very intuitive as we got to learn how to use the various math methods. To proceed, we shall be looking at JavaScript functions.  A function in JavaScript like in every other programming language could be defined as a block of code that is written to perform a particular task, and this function is usually invoked or called before it is being implemented. We have been talking about methods throughout the previous lessons right. Do you know that those methods are actually functions? Yes they are functions. You can now have an overview of the importance of functions in every programming language. How do we create a function in JS? To create a function, you follow the format function functionName(Argument) {//Block of code }. Some functions do have a return val...

JavaScript Math Methods

Hello everyone, and welcome to another exciting JavaScript lesson. In the last lessons you have been seeing other methods being used in JS (for example, the string methods). We shall go further into exploring other methods. This time, it’s going to be math methods. Do not move an inch because it’s going to be a very exciting. Before we look at what a math method is, let’s have an overview of math objects. A math object in JavaScript is a static built-in object that includes properties and methods used in performing mathematical tasks. Talking about math properties, they have the syntax Math.property . Some examples are Math.E that returns Euler’s number, Math.PI that returns PI, Math.LN2 that returns the natural logarithm of 2, and many others. The various JavaScript methods contained in the math object, thus, make mathematical operations easier and reduce effort as well as time in math-oriented programming. Some JS methods include abs( ), ceil( ), cos( ), sqrt( ), pow( ), log( ) ...

How to generate random numbers using NumP1

Hello. Welcome to another edition on this platform. For more better understanding, do checkout our YouTube channel to get the video tutorial. In this article of today, we are going to see how to generate random numbers using any of the following methods: Generating a random number Generating a random float and integer Generating random number arrays Generating random number from an array What is a random number? This is a number which cannot be predicted before its occurrence. This number might not different every time. Programmatically, they are two categories of random numbers:     Pseudo-Random numbers       True Random numbers. Just as programs which are written by programmers are a set of instructions, we must follow an algorithm to generate random numbers. Random numbers which are generated using an algorithm are called Pseudo-Random numbers. To generate a true random number, it is important to get the data from sources such as the keyboards, mou...