Reputation: 17745
I have a grid like this one . The default behavior of this widget is to sort the column when clicking on the header. I want to disable that, and leave only the options in the context menu.
grid.addHeaderClickHandler(new HeaderClickHandler() {
@Override
public void onHeaderClick(HeaderClickEvent event) {
event.getEvent().cancelBubble(true);
event.getEvent().preventDefault();
event.getEvent().stopPropagation();
Window.alert("Event caught");
}
});
The alert gets displayed before the sorting. But when clicking Ok
the default behavior kicks in.
Do you have any suggestions on how to accomplish this?
Upvotes: 0
Views: 1390
Reputation: 17745
Ok I found it grid.getView().setSortingEnabled(false);
. This will disable the sorting when clicking on the header, but keep the menu items in place.
Upvotes: 1
Reputation: 2109
A solution that might work is to use the NativePreviewHandler, something similar to
Event.addNativePreviewHandler(new NativePreviewHandler()
{
@Override
public void onPreviewNativeEvent(final NativePreviewEvent event)
{
if (event.getTypeInt() == Event.ONCLICK)
{
Element targetElement = Element.as(event.getNativeEvent().getEventTarget());
if (!tableHeader.asWidget().getElement().isOrHasChild(targetElement))
{
event.getNativeEvent().stopPropagation();
}
}
}
});
Upvotes: 2
Reputation: 34002
In order to disable sorting you have to configure the column(s) to forbid sorting.
E.g. if you create a column like this (based on the source code from http://www.sencha.com/examples/#ExamplePlace:basicgrid)
ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
disable sorting by adding
symbolCol.setSortable(false);
See http://dev.sencha.com/deploy/gxt-3.0.0/javadoc/gxt/com/sencha/gxt/widget/core/client/grid/ColumnConfig.html#setSortable%28boolean%29 for documentation (and other options).
Upvotes: 1