View Full Version : Cannot get a menu item to sort itself after it has been used.

20 May 2010, 2:57 AM
I have a toolbar in a panel with some buttons in the toolbar. One of these buttons has a drop down menu on it when you click it. One of the other buttons on the toolbar adds items to this menu and tries to sort it so the items in the menu list are always alphabetically sorted. The problem is that adding an item and sorting works if I have not clicked the button which shows the menu but if the menu has been used once or more times the sorting no longer works, the new item is just added to the end of the list.
This is the code I'm using to try and sort the menu

this.getTopToolbar().getComponent('menuPages').menu.items.sort('ASC', function(a,b){
return ((a.text.toLowerCase()>b.text.toLowerCase())?1:-1);
this.getTopToolbar().getComponent('menuPages').menu.doLayout(false, true); Thanks alot

20 May 2010, 3:04 AM
doLayout will not reorder the DOM elements when the items array order has changed.

I suggest you locate the correct location for the new item first and insert() it there instead of add()ing it at the end.

20 May 2010, 4:38 AM
doLayout will not reorder the DOM elements when the items array has changed.

Unless the elements have been removed from the DOM - making isValidParent return false.