Formatting data bound menu

2 Answers 33 Views
Menu
Chris
Top achievements
Rank 1
Iron
Iron
Iron
Chris asked on 18 Dec 2024, 12:15 PM

Hi

I have a data bound menu component where I would like to override the styles of individual items - namely at the moment I would like to make some bold.

What I actually want to do is to render a separator, then a bold header, and then a normal weight list of options - something like :

-----------------------------
Recent Customers
Customer 1
Customer 2
Customer 3
-----------------------------

I do not want them to be a sub menu ideally. I am struggling to work out how to set the class/style of individual menu items.

This is my code for rendering the menu currently, I will add another property to item/subitem as a flag to denote requiring to be bold :

            @(
            Html.Kendo().Menu()
            .Name("mainMenu")                
            .BindTo(Model.Menus.Where(s => s.ParentMenuId == 0), mappings =>
            {
                mappings.For<Welcomm_CRM.Core.Application.Menu>(binding => binding // Define the first level of the Menu.
                .ItemDataBound((item, type) => // Define the mapping between the Menu item properties and the model properties.
                {
                    item.Text = type.MenuTitle;   
                    if (type.MenuSource == 999999)
                    {
                        item.LinkHtmlAttributes.Add(type.ControllerName, type.ActionName);
                    }
                    else if (type.MenuSource == 999998)
                    {
                        item.Separator = true;
                    }
                    else if (type.MenuSource == 0)
                    {
                        item.Url = @Html.Encode(type.Url);
                    }
                }
                )
                .Children(type => Model.Menus.Where(s => s.ParentMenuId == type.MenuId)));
                mappings.For<Welcomm_CRM.Core.Application.Menu>(binding => binding
                .ItemDataBound((item, subtype) =>
                {
                    item.Text = subtype.MenuTitle;                        
                    if (subtype.MenuSource == 999999)
                    {
                        item.LinkHtmlAttributes.Add(subtype.ControllerName, subtype.ActionName);
                    }
                    else if (subtype.MenuSource == 999998)
                    {
                        item.Separator = true;
                    }
                    else
                    {
                        item.Url = @Html.Encode(subtype.Url);
                    }
                })
                );
            })
            )

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 18 Dec 2024, 03:46 PM

Hello Chris,

 

Thank you for contacting us.

The described scenario is very suitable for the DropDownList Grouping feature:
https://demos.telerik.com/aspnet-mvc/grid/toolbar-template

Do you like this idea? Is the answer helpful?

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Chris
Top achievements
Rank 1
Iron
Iron
Iron
answered on 18 Dec 2024, 04:06 PM

Hi

No sorry it needs to be a menu as it's part of the overall navigation - I have a menu bar like below :

And when I drop down an option I want the part highlighted to be bold as a header :

Eyup
Telerik team
commented on 23 Dec 2024, 03:00 PM

Got it.

I will prepare a new sample with the Menu and send it to you.

Eyup
Telerik team
commented on 28 Dec 2024, 09:53 AM

I have prepared a full-fledged project with the requested implementation:

Can you run the attached sample and let me know if you find it helpful?

Chris
Top achievements
Rank 1
Iron
Iron
Iron
commented on 02 Jan 2025, 11:52 AM

Hi - sorry for the delay in replying, it is our first day back in the office. This works very well, thank you for that.
Tags
Menu
Asked by
Chris
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Eyup
Telerik team
Chris
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or