PDA

View Full Version : How to remove items from Hmenu? (grid column menu)



Jack9
8 Jul 2010, 8:51 AM
Without subclassing, it makes sense to put this in afterrender and that this should work:


//thisGrid.getView().hmenu.get('asc').hide();
//thisGrid.getView().hmenu.get('desc').hide();
//thisGrid.getView().hmenu.get('columns').hide();
//thisGrid.getView().hmenu.get('groupBy').hide();
//thisGrid.getView().hmenu.get('showGroups').hide();

// trying to get rid of everything, including the pesky separators
for(var i=0;i<thisGrid.getView().hmenu.items.getCount();i++){
thisGrid.getView().hmenu.items.removeAt(i);
}
Can someone tell me why it doesnt? What is the correct way?

Condor
8 Jul 2010, 10:21 AM
If you want remove all items, then why not configure you grid with enableHdMenu:false?

Or if you don't want to remove all, then you could configure the grid with enableColumnHide:false and/or the column with sortable:false, menuDisabled:true and/or groupable:false.

ps. You can't remove items from the menu, because Ext expects them to be present, but you can hide them.

Jack9
8 Jul 2010, 10:40 AM
I am rebuilding the menu dynamically. The native Hdmenu items are not desired. Sortable/groupable just greys out the items and hiding leaves the separators intact.

I know there's a way to remove the separators. I did it sometime in the last year, I just don't remember how and curiously, there isn't a post about this yet on the community forums.

Condor
8 Jul 2010, 12:17 PM
You will need to hide the original menu items (because gridview needs to refer to them).

You can however remove the separator, but this is done with:

thisGrid.getView().hmenu.remove(i);
(hmenu is an Ext.Container)

Jack9
8 Jul 2010, 1:08 PM
This is effective:


var hdmenu = thisGrid.getView().hmenu;
hdmenu.get('asc').hide();
hdmenu.get('desc').hide();
hdmenu.get('columns').hide();
hdmenu.get('groupBy').hide();
hdmenu.get('showGroups').hide();
hdmenu.items.removeAt(4);
hdmenu.items.removeAt(2);

The separators are not important to the interface and dont have an associated hide (although I guess I could have applied a display:none style). Removal works for me.