Create admin grid listing in Magento 2
Create Model File Allnews.php
Rsgitech\News\Model\Allnews.php
Create Resource Model
Rsgitech\News\Model\ResourceModel\Allnews.php
Define table in resource model
Create Collection
Rsgitech\News\Model\ResourceModel\Allnews\Collection.php
Define model and resource model
Create Grid Collection
Rsgitech\News\Model\ResourceModel\Allnews\Grid\Collection.php
Create file status.php
Rsgitech\News\Model\Allnews\Source\Status.php
It is dropdown of status like as enabled and disabled
Create Action Column of Grid Items
Rsgitech\News\Ui\Component\Listing\Column\AllnewsActions.php
You can create action of grid items like edit, delete, view etc.
Create file di.xml
Rsgitech\News\etc\di.xml
Controller Action Index.php
Rsgitech\News\Controller\Adminhtml\AllNews\Index.php
Change controller file like this
Create view file of ui component
Rsgitech\News\view\adminhtml\ui_component\news_allnews_listing.xml
Layout
Rsgitech\News\view\adminhtml\layout\news_allnews_index.xml
Load uiComponent news_allnews_listing in news_allnews_index.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