PDA

View Full Version : Grid Column Header Menu



slynch
27 Jan 2010, 9:06 AM
Hi,

Is it possible to manipulate the default drop down menu attached to each column header in the gxt grid. I would like to implement something similar to the EXT-JS grid example where you add the filter option to each column menu:

http://www.extjs.com/deploy/dev/examples/grid-filtering/grid-filter-local.html

Thanks,
Susan.

terciofilho
27 Jan 2010, 1:03 PM
Yes, we can! :-P

That's the way I did it:



this.grid.addListener(Events.HeaderContextMenu, new Listener<GridEvent<ModelData>>()
{
public void handleEvent(final GridEvent<ModelData> ge)
{
// Add a Menu Item
final MenuItem menuItem = new MenuItem("New Menu Item");
menuItem.addListener(Events.Select, new Listener<BaseEvent>()
{
public void handleEvent(final BaseEvent be)
{
// Do some stuff!
}
});
ge.getMenu().add(menuItem);
}
});

slynch
1 Feb 2010, 8:54 AM
Thanks for the solution!

John99
1 Feb 2010, 12:41 PM
you need to extend GridView and override createContextMenu method. Then set your gridview to the grid:


@Override
public Menu createContextMenu(final int colIndex) {

final Menu menu = super.createContextMenu(colIndex);

final CheckMenuItem filter = new CheckMenuItem();
filter.setHideOnClick(false);
filter.setText("Filter");
filter.setChecked(false);

....

filter.setSubMenu(sf.getSubMenu());

menu.add(new SeparatorMenuItem());
menu.add(filter);

return menu;
}