Lives: 30

Inserting menu on client

This post has 5 replies

Top 50 Contributor
Posts: 89
markdavison Posted: Tue Apr 3, 2007 @ 6:19 AM
Hi,

I am trying to insert a menu item into a menu on the client through JavaScript.

I have tried the following but the menu items are always being put at the bottom of my menu rather than at the start of the menu:

var menuitems = ToolBar_mnuNew.get_items();
var newMenuItem;

newMenuItem= new ComponentArt.Web.UI.MenuItem();
newMenuItem.set_text('Standard Toolbar Item 1');
newMenuItem.set_clientSideCommand("alert('clicked');");
newMenuItem.setProperty("NonStandard","1");
menuitems.insert(newMenuItem,0);

newmenuitem = new ComponentArt.Web.UI.MenuItem();
newMenuItem.set_text('Standard Toolbar Item 2');
newMenuItem.set_clientSideCommand("alert('clicked');");
newMenuItem.setProperty("NonStandard","1");
ToolBar_mnuNew.get_items().insert(newMenuItem,0);

How can I insert the menu items at the start of the menu?

Regards,

Mark
Top 25 Contributor
Posts: 336
sadat Posted: Tue Apr 3, 2007 @ 2:32 PM
I am afraid, this is a bug.
We don't have a fix at this point.

We are sorry for any inconvenience it might cause and thank you for understanding.
Not Ranked
Posts: 9
dilbgmbh Posted: Thu Jan 28, 2010 @ 6:23 AM
I have this bug too and I am using Framework 2009.3

In 2007 you recognized this as a bug. Now we are in the year 2010 and the bug is still alive?
Top 10 Contributor
Posts: 639
harish Posted: Thu Jan 28, 2010 @ 7:09 AM

Hello,

 

I am afraid the defect #D6190 (description:  "itemCollection.insert() client-side method ignores index on root items" ) is still open. I have linked this forum link with the defect so that you will be automatically notified when the service release(hot fix) is available.

 

We apologize for any inconvenience faced.

 

Thanks.

 

Harish Malhotra

Not Ranked
Posts: 3
mueller-inc Posted: Wed May 12, 2010 @ 9:04 AM
I just ran into this bug as well on the latest release (2010.1.2381).  Three years old ... wow (sad)

I wrote this as a workaround, which worked perfectly for my needs.
This script, adds an InsertItem method onto the ComponentArt.Web.UI.Menu prototype.
Then you can use yourMenuObject.InsertItem(yourNewMenuItemObject, index)

    // extend the ComponentArt Menu class with an InsertItem method
if (ComponentArt && ComponentArt.Web && ComponentArt.Web.UI && ComponentArt.Web.UI.Menu) {
if (!ComponentArt.Web.UI.Menu.prototype.InsertItem) {
ComponentArt.Web.UI.Menu.prototype.InsertItem = function(menuItem, index) {
// This method is provided as a workaround to a bug in the ComponentArt menu
// http://www.componentart.com/community/forums/p/29484/97712.aspx#97712

// get array of current items
var currentMenuItems = this.get_items().get_itemArray();
// insert new item at requested index
currentMenuItems.splice(index, 0, menuItem);
// Only call beginUpdate if not already updating.
var alreadyUpdating = this.get_isUpdating();
if (!alreadyUpdating)
this.beginUpdate();
this.get_items().clear();
// append menu items (in order)
for (var i = 0; i < currentMenuItems.length; i++)
this.AddItem(currentMenuItems[i]);
if (!alreadyUpdating)
this.endUpdate();
}
}
}
Top 10 Contributor
Posts: 639
harish Posted: Wed May 12, 2010 @ 9:09 AM

Hello,

 

Thanks for posting the workaround.

 

Harish Malhotra

Page 1 of 1 (6 items)

Copyright © 2010 ComponentArt, Inc. All rights reserved.