Magento Tutorials

How to Add Sticky Header Component in Magento 2

Hello Magento Friends,

Today’s Tutorial is about How to Add Sticky Header Component in Magento 2.

The sticky header component is the fixed area on the header section of the webpage when the user scrolls down. The main menu, top links, cart, logo can appear in the sticky header of your Magento 2 store. Also, allow customers to add-to-cart any product even if the product page is scrolled down by displaying the product components like product name, image, price, add-to-cart at the sticky header.

When you go to the Magento 2 Admin product management page, you will see the sticky header component.

Let’s learn How to Add Sticky Header Component in Magento 2 

Steps to Add Sticky Header Component in Magento 2:

Step 1: The sticky is applied for the display of the grid with the configuration

<container name="sticky">
   <argument name="data" xsi:type="array">
       <item name="config" xsi:type="array">
           <item name="component" xsi:type="string">Magento_Ui/js/grid/sticky/sticky</item>
           <item name="toolbarProvider" xsi:type="string">...</item>
           <item name="listingProvider" xsi:type="string">...</item>
       </item>
   </argument>
</container>

Step 2: You can also use sticky in your custom grid. For that go to the below path:

app\code\vendor\extension\view\adminhtml\ui_component\custom_grid_listing.xml

And add the below lines of code:

<container name="sticky">
   <argument name="data" xsi:type="array">
       <item name="config" xsi:type="array">
           <item name="component" xsi:type="string">Magento_Ui/js/grid/sticky/sticky</item>
           <item name="toolbarProvider" xsi:type="string">custom_grid_listing.custom_grid_listing.listing_top</item>
           <item name="listingProvider" xsi:type="string">custom_grid_listing.custom_grid_listing.custom_grid_columns</item>
       </item>
   </argument>
</container>

Step 3: To change the template of the sticky header, you can use the following configuration:

<container name="listing_top">
   <argument name="data" xsi:type="array">
       <item name="config" xsi:type="array">
           <item name="template" xsi:type="string">ui/grid/toolbar</item>
           <item name="stickyTmpl" xsi:type="string">ui/grid/sticky/toolbar</item>
       </item>
   </argument>
</container>

To get more details, check the below file

vendor\magento\module-cms\view\adminhtml\ui_component\cms_page_listing.xml 

Final Say:

This way you can Add Sticky Header Component in Magento 2. You can also integrate Magento 2 Sticky Add To Cart extension to your store for displaying an attractive sticky bar. Customize your Magento 2 store by hiring our certified Magento Developers. For any difficulties, let me know in the comment section below. Share the article with your Magento colleagues. Stay in the know for more Magento tutorials.

Happy Reading!

Click to rate this post!
[Total: 12 Average: 4.4]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

Mastering Tailwind CSS in Laravel: A Comprehensive Guide

Tailwind CSS has emerged as a powerful utility-first CSS framework, offering developers a unique approach…

46 mins ago

React Native or Flutter in 2024

The mobile app development field has witnessed a rapid revolution over the past few years.…

2 days ago

Magento 2: How To Call JS on the Checkout Page?

Hello Magento mates, Today we will learn to add a call JS on the checkout…

5 days ago

Boost Your SEM Game: Unveiling the Top 10 Tools for Marketers in 2024

Business survival in today’s digital world has become extremely difficult. Using traditional marketing techniques is…

6 days ago

Five Essential Payroll Compliance Tips for eCommerce Startups

Are you setting up a payroll system for your eCommerce startup? Ensuring compliance with myriad…

7 days ago

Optimizing Laravel Blade: Unlocking Advanced Fetcher Techniques

In the expansive universe of Laravel development, Blade serves as the stellar templating engine, propelling…

7 days ago