How can I create a search engine in the main menu of the application?

Hi!

The Jmix UI Samples application has a fully custom loading menu.

If you want to implement the same approach, you need to follow these steps:

  1. Define your custom menu scheme and implement it.
    Example: src/main/resources/io/jmix/uisamples/menu
  2. Implement the loader: io.jmix.uisamples.config.UiSamplesMenuConfig
  3. And after all, implement the search-field: io.jmix.uisamples.view.sys.main.MainView#initSideMenu

You can use standard flowui_MenuConfig as an example or extend it: io.jmix.flowui.menu.MenuConfig.
If you don’t want to extend the standard menu scheme and just want to embed a menu-search mechanism, you should implement menu loading in MainView based on the original MenuConfig.

The error you encountered is caused by the fact that the original MenuConfig returns root items of io.jmix.flowui.menu.MenuItem type.

Look at how the search works: io.jmix.uisamples.view.sys.main.MainView#search

  1. First, all menu items are removed.
  2. Then all possible menu items are loaded.
  3. Next are the menu items that match the search criteria (io.jmix.uisamples.view.sys.main.MainView#findItemsRecursively).
  4. For all found elements, the parent menu items are expanded.
  5. At the end, all unexpanded menu items are deleted: io.jmix.uisamples.view.sys.main.MainView#removeNotRequestedItems

I hope my answer will help you.

Regards,
Dmitriy