DEV Community

Tu Nguyen
Tu Nguyen

Posted on • Edited on

2

Magento2 ui component in deep

From this tutorial i will show you how to get info from some main component in magento 2 by javascript

All components defined in below file
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Ui/view/base/ui_component/etc/definition.xml

If you work with components in magento you possible may related with uiregistry. This is ultility component allow you access to specific component.

Playground for work with component from browser

Go to product list page of magento in admin dashboard
Open chrome browser > Console tab

requirejs('uiRegistry').get('%componentName%');

componentName is string name of component.

1 Listing component

Source file
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Ui/view/base/web/js/grid/listing.js

There is alot place magento use this component such as: Product listing, Order listing, cms page listing

Example

var productrows = requirejs('uiRegistry').get('product_listing.product_listing.product_columns').rows

Above will return current object contain rows of products

[{product1},{product2},so on]

OR

var productrows = requirejs('uiRegistry').get('product_listing.product_listing_data_source').data['items']

var components = requirejs('uiRegistry').get('product_listing.product_listing.product_columns').elems()

2 Form component

Source file
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Ui/view/base/web/js/form/form.js

Continuing...

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay