How to add grid items in Magento 2
Create Allnews Interface
Rsgitech\News\Api\Data\AllnewsInterface.php
Create interface for fields
Implement Interface in Allnews Model
Rsgitech\News\Model\Allnews.php
Create AllnewsRepositoryInterface
Rsgitech\News\Api\AllnewsRepositoryInterface.php
Create AllnewsRepositoryInterface for save, delete, getById, deleteById
Create class AllnewsRepository
Rsgitech\News\Model\AllnewsRepository.php
Create class AllnewsRepository and implements interface AllnewsRepositoryInterface
Resource model Allnews
Rsgitech\News\Model\ResourceModel\Allnews.php
Here set created at and updated at date before save
Create file di.xml
Rsgitech\News\etc\di.xml
Create file acl.xml
Rsgitech\News\etc\acl.xml
Create ACL file for user authorization
Create block Allnews
Rsgitech\News\Block\Adminhtml\Allnews.php
Create Grid Block
Rsgitech\News\Block\Adminhtml\Allnews\Grid.php
Create GenericButton Block
Rsgitech\News\Block\Adminhtml\Allnews\Edit\GenericButton.php
Create BackButton Block
Rsgitech\News\Block\Adminhtml\Allnews\Edit\BackButton.php
Create DeleteButton Block
Rsgitech\News\Block\Adminhtml\Allnews\Edit\DeleteButton.php
Create ResetButton Block
Rsgitech\News\Block\Adminhtml\Allnews\Edit\ResetButton.php
Create SaveAndContinueButton Block
Rsgitech\News\Block\Adminhtml\Allnews\Edit\SaveAndContinueButton.php
Create SaveButton Block
Rsgitech\News\Block\Adminhtml\Allnews\Edit\SaveButton.php
Create Controller Action NewAction
Rsgitech\News\Controller\Adminhtml\Allnews\NewAction.php
Create new grid item
Create Controller Action Save
Rsgitech\News\Controller\Adminhtml\Allnews\Save.php
Create ui component form
Rsgitech\News\view\adminhtml\ui_component\news_allnews_form.xml
Create Layout
Rsgitech\News\view\adminhtml\layout\news_allnews_edit.xml
Load uiComponent news_allnews_form in news_allnews_edit.xml file
Then run below commands
Complete!!
Download source code: Download
This lesson also available on YouTube
More Posts - Magento 2 Module Development
- Create admin menu in magento 2
- Create system config in magento 2
- Create helper and get system config value Magento 2
- How to create table and install sample data in Magento 2
- Create collection in Magento 2
- Create admin grid listing in Magento 2
- How to add grid items in Magento 2
- How to edit grid items in Magento 2
- How to delete grid items in Magento 2
- How to show collection on frontend with pagination in Magento 2
- How to get single record from collection in Magento 2