Font Size:
Ask Joget AI

Always Keep Active UI Menu in Sidebar in View

Introduction

When your Joget application’s UI contains many categories and menus, navigating through the sidebar can become cumbersome. By default, upon clicking on any UI menu, the sidebar will default to the top position. So, if the currently active UI menu is at the bottom region of the sidebar, it requires scrolling to get to it, making it challenging to access menus at the bottom quickly. This guide will show you how to automatically scroll the sidebar to keep the active menu in view, enhancing the user experience.

This script does not work with the DX X-Admin and V5 Janux themes.

How does it work?

This solution involves adding custom JavaScript to your UI configuration. The script identifies the active menu item and automatically scrolls the sidebar to keep it visible, preventing users from having to scroll through the sidebar to find the active menu manually.

To implement this, follow these steps:

  1. Go to the UI Builder. 
  2. Click Settings.
  3. Within the settings menu, go to the Theme tab.
  4. Click the Advanced tab.
  5. Scroll down to the Custom JavaScript field.
  6. Paste the following code:
    $(function () {
        function keepActiveMenuInView() {
            // the element the theme attached its custom scrollbar to:
            // #navigation (DX 8 / DX 9 themes) or #sidebar (DX Progressive, V6 Universal)
            var $scroller = $("#navigation, #sidebar").filter(function () {
                return !!$(this).data("mCS");
            }).first();
            var $active = $scroller.find("li.menu.active");   // the active menu, not its category
            if (!$scroller.length || !$active.length) {
                return;                                        // theme without a custom scrollbar, or no active menu
            }
            // if the menu's category is collapsed, bring the category header into view instead
            var $target = $active.is(":visible") ? $active : $active.closest("li.category");
    
    
            $scroller.mCustomScrollbar("update");             // re-measure after the active category has expanded
    
    
            // do nothing if it is already fully visible (avoids jumping after a sidebar click)
            var box = $scroller.find(".mCustomScrollBox")[0].getBoundingClientRect();
            var item = $target[0].getBoundingClientRect();
            if (item.top >= box.top && item.bottom <= box.bottom) {
                return;
            }
            $scroller.mCustomScrollbar("scrollTo", $target, { scrollInertia: 0 });
        }
    
    
        // full page load (refresh, direct link, bookmark, non-AJAX themes)
        setTimeout(keepActiveMenuInView, 500);
    
    
        // AJAX themes: page changes that were not triggered from the sidebar itself
        $(document).off("page_loaded.keepActiveMenu").on("page_loaded.keepActiveMenu", function () {
            setTimeout(keepActiveMenuInView, 100);
        });
    });
  7. Save your changes.
  8. Preview the userview to see the automatic scrolling in action.

Download sample app

Download the sample app for Always Keep Active UI Menu in Sidebar in View
Created by Aadrian Last modified by Nur Baizura Badrul Sham on Oct 27, 2026