PDA

View Full Version : What is the best way to modify the Ext.grid.header.Container menu?



jjohnso2
18 May 2012, 10:58 AM
I would like to add an item to the grid header menu:

35409

My solution is to create a new Ext.grid.feature.Feature sub-class, listen for the "menucreate" event fired by Ext.grid.header.Container, and then modify the menu. Here's an example:


attachEvents: function(){
this.view.getHeaderCt().on('menucreate', this.onMenuCreate, this);
},

onMenuCreate: function(ct, menu){
menu.add(/* item def'n here */);
}

This works fine, but I want to make sure I'm doing things the correct way. I've looked at the source for the Ext.grid.feature.Grouping and Ext.grid.Lockable classes, both of which modify the column header menu. Each class overrides headerCt.getMenuItems with a custom function. Why do these classes override headerCt.getMenuItems instead of listening for the "menucreate" event?

20 May 2012, 4:12 AM
Your pattern is fine.

They override because it's the pattern they chose, as events are considered expensive. That's my hunch :)

jjohnso2
21 May 2012, 6:14 AM
Thanks, Jay. That makes sense.