This is a migrated thread and some comments may be shown as answers.

CloseOnClick & DataUrlField

11 Answers 113 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Jerome
Top achievements
Rank 1
Jerome asked on 30 Jan 2020, 09:55 PM

I am not sure why, but when I use DataUrlField, the subMenu refuses to close and stays open.

I even tried forcing the issue by using CloseOnClick(true). If I comment out the DataUrlField, then the menu works as I would expect, closing on click, or if I set it to CloseOnClick(false) it stays open as expected.  As soon as I add the DataUrlField it seems to force the CloseOnClick to false.  

 

Any ideas what I might be doing wrong, or a workaround?

 

Here is the snippet:

@(Html.Kendo().Menu()
               .Name("absMenu")
               .DataTextField("Label")
               .DataSource(ds => ds.Read("GetNavMenus", "NavMenus")
               .Model(model => model.Children("hasChildren")))
               .Orientation(MenuOrientation.Vertical)
               .CloseOnClick(true)
               .HighlightPath(false)
               .Animation(a => a.Open(o => o.SlideIn(SlideDirection.Right).Duration(100)))
               //.DataUrlField("Action")
               )

11 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 04 Feb 2020, 12:51 PM

Hi Jerome,

I tested the Menu with the posted configuration and at my end I see no difference in the way the sub menus close with or without DataUrlField set in the Menu. See the .zipped video, which shows how the sub menus close. Note that I am not clicking the parent items, since they also have urls associated with them and will navigate on click. I am not sure whether that is the case with your Menu, or you are navigating only on sub item selection.

Attached you can find a sample runnable project, which I used to test the scenario. Give it a try and let me know in case I am missing something with regard to reproducing the problematic behavior.

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Jerome
Top achievements
Rank 1
answered on 06 Feb 2020, 02:44 PM

Ivan,

Thanks for the followup!  Actually your sample is doing the same thing... when you click on the subMenu item, the "action" happens, but the submenu doesn't close.  The reason you can't see it, is because your action is reloading the page from Wikipedia.  If you change the "action" to load the url link in a new page, then go back to your Home Index page, you will notice that the subMenu is still open.  I have attached a slightly modified version of the sample app and have attached... click on Root1->Item 2.1, let wikipedia load, then switch back to the Home tab... 

I also tried this using the Events=>Selected option instead of using the DataUrlField, and get the same eaffect.  See the 2nd Menu for an example of this method.

Maybe I am missunderstanding how calling JS from DataUrlField or an event affects the Menu JS?

Thanks,

Jerome.

PS: the forum won't allow me to attach a ZIP file.... how can I upload it?

0
Jerome
Top achievements
Rank 1
answered on 06 Feb 2020, 03:01 PM

Change the Action to:

new SubItem() { SubItemID = 7, Label = "Item 2.1",  Action = "javascript:window.open(\"https://www.wikipedia.org\", \"Wikipedia\"); void(0);", hasChildren = null },

(for some reason, the forum's formating options won't allow me to make that a code block)

 

and then I tried this for the Events (sorry for the ugliness in this post, still wont let me format it as code):

<div style="width: 200px;">     @(Html.Kendo().Menu()         .Name("absMenu")         .DataTextField("Label")         .DataSource(ds => ds.Read("GetNavMenus", "Home")         .Model(model => model.Children("hasChildren")))         .Orientation(MenuOrientation.Vertical)         .CloseOnClick(true)         .HighlightPath(false)         .Animation(a => a.Open(o => o.SlideIn(SlideDirection.Right).Duration(100)))         .DataUrlField("Action")     )</div><div style="width: 200px;">     @(Html.Kendo().Menu()         .Name("absMenu2")         .DataTextField("Label")         .DataSource(ds => ds.Read("GetNavMenus", "Home")             .Model(model => model.Children("hasChildren")))         .Orientation(MenuOrientation.Vertical)         .CloseOnClick(true)         .HighlightPath(false)         .Animation(a => a.Open(o => o.SlideIn(SlideDirection.Right).Duration(100)))         .Events(e => e.Select("LoadWiki"))         //.DataUrlField("Action")         )</div>                                  <script>     function LoadWiki(e) {         window.open("https://www.wikipedia.org", "Wikipedia"); S    } </script>

0
Jerome
Top achievements
Rank 1
answered on 06 Feb 2020, 03:14 PM
There is an "S" typo at the end of the JS function LoadWiki, that was typed in error as I was posting the last post... please delete the erroneous character before trying to use the the code.
0
Jerome
Top achievements
Rank 1
answered on 06 Feb 2020, 03:18 PM
0
Accepted
Ivan Danchev
Telerik team
answered on 11 Feb 2020, 01:52 PM

Hi Jerome,

Thank you for the additional details. I've logged this issue for fixing and opened a bug report item in our Feedback Portal on your behalf: https://feedback.telerik.com/aspnet-core-ui/1453233-menu-submenu-does-not-close-on-item-selection-if-navigation-is-triggered-programmatically

For your involvement in identifying this issue with the Menu, I updated your Telerik points.

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Jerome
Top achievements
Rank 1
answered on 11 Feb 2020, 02:31 PM

@Ivan,

Ah man, I was really hoping it was something I was doing wrong... 🤨  (that is usually the case 99.999%, just ask my wife)

Thank you for all your help!

Jerome.

0
Ivan Danchev
Telerik team
answered on 14 Feb 2020, 10:16 AM

Jerome,

That was a good one :)

As a temporary workaround, consider closing the submenu by calling the Menu's close API method in the Select event handler:

function LoadWiki(e) {
  e.sender.close();
}

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Jerome
Top achievements
Rank 1
answered on 18 Feb 2020, 01:09 PM

@Ivan,

Thanks for the workaround, as that does indeed close the submenu.  Now I have to figure out how to dynamically store subitem's action somewhere, and then retrieve that value from "e" (LoadWiki(e))...

window.open(e.sender.????)

could I use DataContentField or some other attribute?

The online docs and demos are very sparse on this ... :( unless I am looking in the wrong places... I even looked at MVC and AJAX

0
Accepted
Ivan Danchev
Telerik team
answered on 21 Feb 2020, 01:54 PM

Jerome,

There is no need to store the action in another field, because you can get the selected item's action from the dataItem. If we use the previous example, in which the url is saved in the Action field, you can access that field value, as shown below:

function LoadWiki(e) {
	var itemUid = $(e.item).attr("data-uid");
	var dataSource = e.sender.dataSource;
	var dataItem = dataSource.getByUid(itemUid);

    alert(dataItem.Action)
} 

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Jerome
Top achievements
Rank 1
answered on 21 Feb 2020, 02:04 PM

That is awesome!!

That actually helps solve a few other things I was trying to figure out.  

Thanks!!!!

Tags
Menu
Asked by
Jerome
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Jerome
Top achievements
Rank 1
Share this question
or