Create uiComponent for the simplenews grid list
This tutorials will replace the news grid list for the previous one, Magento 2: A full Magento 2 Module, with new created uiComponent. uiComponent is the new feature for Magento 2 by utilizing the modern JavaScript frameworks, requireJs, knockoutJs, underscoreJs. It’s very complicated unless you are familiar with these frameworks. Today I will show you how to generate it step by step and replace the news grid list from last tutorial, Magento 2: A full Magento 2 Module.
Create new uiComponent xml file
#app/code/Jeff/SimpleNews/view/adminhtml/ui_component/simplenews_listing.xml - simplenews_listing.simplenews_listing_data_source
- simplenews_listing.simplenews_listing_data_source
- simplenews_listing_columns
- add
- Add New
- primary
- */News/new
Jeff\SimpleNews\Ui\Component\Listing\DataProviders\Simplenews\Listing simplenews_listing_data_source id id - id
- Magento_Ui/js/grid/provider
- false
- 55
- id
- 10
- textRange
- desc
- ID
- text
- Title
- 20
- text
- Summary
- 30
- text
- Description
- 40
- text
- Create At
- 50
- false
- 107
- id
- 200
Create Data Provider for uiComponent
#app/code/Jeff/SimpleNews/Ui/Component/Listing/DataProviders/Simplenews/Listing.php collection = $collectionFactory->create(); } }
Create Page Actions for the Grid List
#app/code/Jeff/SimpleNews/Ui/Component/Listing/Column/Simplenewslisting/PageActions.php getData("name"); $id = "X"; if(isset($item["id"])) { $id = $item["id"]; } $item[$name]["view"] = [ "href"=>$this->getContext()->getUrl( "simplenews/news/edit",["id"=>$id]), "label"=>__("Edit") ]; } } return $dataSource; } }
Update simplenews_news_index.xml file to use the new uiComponent
#app/code/Jeff/SimpleNews/view/adminhtml/layout/simplenews_news_index.xml
After clear cache, you can check the simple news grid list. The appearance is the same. But you will notice the list is loaded by JavaScript’s Ajax way by showing the spinner image first then the grid list.
I hope this tutorial will help you generate your own uiComponent for the grid list.
During Loading:
Loaded Successfull: