cancel
Showing results for 
Search instead for 
Did you mean: 

MenuBar in sapui5

Former Member
0 Kudos

Hi All,

I have been trying to develop a simple page with SAPUI5 controls. I have created a Menu Bar and Menu Bar Items with the following kind of code.

var oMenuBar = new sap.ui.commons.MenuBar("menuBar");

var oMenuBarItem1 = new sap.ui.commons.MenuItem("menuBar-item-1",{text:"Home", enabled: true});

oMenuBar.addItem(oMenuBarItem1);

A Menu called "Home" is created. Now if I click on this Menu, it should go to another page. What methods are used to add hyper links to menu items? Can you suggest a sample code?

Thanks & Regards,

Saranya

Accepted Solutions (1)

Accepted Solutions (1)

former_member182650
Contributor
0 Kudos

Hi,

You could attach select event and navigate to an url:

oMenuBarItem1.attachSelect(function navigateEntireToUrl(evt) {

document.location = 'http://www.your_url.com';

});

Kind regards,

Former Member
0 Kudos

Hi,

Thanks for your reply!

This is the code I typed but it's not working. What could have gone wrong?

var oMenuBar = new sap.ui.commons.MenuBar("menuBar");

var oMenuBarItem1 = new sap.ui.commons.MenuItem("menuBar-item-1",{text:"Project"});

oMenuBar.addItem(oMenuBarItem1);

oMenuBarItem1.attachSelect(function navigateEntireToUrl(evt) {

document.location = 'http://www.google.com';

});

Regards,

Saranya

former_member182650
Contributor
0 Kudos

Try this:

var oMenuBar = new sap.ui.commons.MenuBar("menuBar");

var oMenuBarItem1 = new sap.ui.commons.MenuItem("menuBar-item-1",{text:"Root"});

var oSubMenu1 = new sap.ui.commons.Menu("menuBar-submenu1");

oMenuBarItem1.setSubmenu(oSubMenu1);

var oSubMenuItem1 = new sap.ui.commons.MenuItem("menuBar-subitem-1",{text:"Open Google"});

oSubMenuItem1.attachSelect(function navigateEntireToUrl(evt) {

document.location = 'http://www.google.com';

});

oSubMenu1.addItem(oSubMenuItem1);

oMenuBar.addItem(oMenuBarItem1);

Kind regards,

former_member184867
Active Contributor
0 Kudos

Hi Saranya,

why don't you create a JSbin sample ..

Regards,

Atanu

Former Member
0 Kudos

It works, Thank you!

But we can't create a hyper link in the main menu itself? Do we necessarily have to create a sub-menu?

Thanks & Regards,

Saranya

former_member182650
Contributor
0 Kudos

If you want this behavior in your root menu, it has no sense use menubar, you could use a simple button instead.

Regards

Former Member
0 Kudos

Okay, Thank you!

Regards,

Saranya

Former Member
0 Kudos

I'm not much familiar with that, can you suggest some documents and links that would help me.

Regards,

Saranya

Answers (0)