We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Menu Bar change item text

Hello,

Is it possible to change the text of a MenuItem of a EjsMenu control?

I tried something like this without success:

<EjsMenu Items="@_menuItems">
    <MenuEvents ItemSelected="MenuItemSelected" />
</EjsMenu>

private List<MenuItem> _menuItems = new List<MenuItem>
    {
        new MenuItem{ Text = "Item 1" },
        new MenuItem{ Text = "Item 2" },
        new MenuItem{ Text = "Item 3" }
    };

In a button click:
_menuItems[1].Text = "Test";
StateHasChanged();


Thank you

1 Reply

AD Arunkumar Devendiran Syncfusion Team December 19, 2019 07:43 PM UTC

Hi Fabrizio Alessandro, 
 
Thanks for your patience. 
 
We have checked your reported query and you can achieve this by using deserialize the serialized menuItems and we have created the sample for your requirement, in that we have change to the menu items text on button click. Please refer the below code snippet and sample link. 
 
Index.razor 
 
@using Newtonsoft.Json; 
 
<EjsMenu Items="@_menuItems"></EjsMenu> 
<EjsButton @onclick="onClick" Content="Click"></EjsButton> 
@code { 
    private List<MenuItem> _menuItems = new List<MenuItem> 
{ 
        new MenuItem{ Text = "Item 1" }, 
        new MenuItem{ Text = "Item 2" }, 
        new MenuItem{ Text = "Item 3" } 
    }; 
    private void onClick() 
    { 
        List<MenuItem> NewMenuItems = JsonConvert.DeserializeObject<List<MenuItem>>(JsonConvert.SerializeObject(_menuItems)); 
        NewMenuItems[1].Text = "Text"; 
        this._menuItems = NewMenuItems; 
    } 
} 
 
 
 
Sample Link: 
 
Could you please check the above link and get back to us with more information if we misunderstood your requirement or need further assistance. 
 
Regards, 
Arunkumar D 


Loader.
Up arrow icon