Hello
Telerik, please correct me if I'm wrong in any case.
I want to simply exchange one menu item by another one. A simple use case is a state change like "Show Tooltips" and "Hide Tooltips". For this scenario I saw two possibilites:
1. Replace menu text visa versa
2. Add new menu element after existing element and then remove first element
Replace menu text visa versa
This approach took me a while. With JQuery its a singe line, assuming you are using JQuery. Switching menu text only will visually screw up your menu element. This will happen because you remove also a class that was initially set on the element by defining the menu. So therefore you need to add the class again as well:
$('#hidetip').html('<
span
class
=
"k-link"
>Tooltips anzeigen</
span
>');
-> Pretty simple, you just need to know it.
Hint: Use an additional attribute on the menu element like "state" (hidden, visible) to check/set its current state
Add new menu element after existing element and then remove first element
There is a menu function available called insertAfter that is obvious to use in this case. The main problem here is that you can't attach an ID or classes that way. I tried this:
var mainmenu = $("#mainmenu").data("kendoMenu");
mainmenu.insertAfter(
{id: "showtip", text: "Show tooltips"},
"#hidetip"
);
-> Text was attached but not the ID.
Another one I tried after finding this forum entry: See here
var mainmenu = $("#mainmenu").data("kendoMenu");
mainmenu.insertAfter(
{text: "<
li
id
=
'showtip'
>Show tooltips</
li
>",
encoded: false}, // to interpret text as HTML not as pure text
"#hidetip"
);
-> Text of element will be screwed up again inside menu. My initial thought was to add the class again:
{text: "<
li
id
=
'showtip'
><
span
class
=
'k-link'
>Show tooltips</
span
></
li
>",
encoded: false},
-> Text inside menu is still screwed up and a further (empty) line was added after "Show tooltip" item (with the span class). Maybe I did something wrong here, just dunno what. I can live with the first solution.