Hi,
I want to customize the header context menu by handling the onclick event of the menu items. I tried to override the getHeaderContextMenuItems method like below. But I am not able to retrieve the submenu items shown for Group by (by Day, by Week etc.) in case of date type field. Please help me with this.
protected MenuItem[] getHeaderContextMenuItems(final Integer fieldNum) {
MenuItem[] items = super.getHeaderContextMenuItems(fieldNum);
for (int i = 0; i < items.length; i++) {
final MenuItem item = items[i];
final String itemTitle = item.getTitle();
item.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
if("Sort Ascending".equals(itemTitle)){
sort(fieldNum, SortDirection.ASCENDING);
}else if("Sort Descending".equals(itemTitle)){
sort(fieldNum, SortDirection.DESCENDING);
}else if(item.getTitle().equals("Clear Sort")){
clearSort();
}else if(itemTitle.startsWith("Group by")){
groupBy(getFieldName(fieldNum));
//mycode
}else if(itemTitle.equals("Ungroup")){
ungroup();
//mycode
}else if(itemTitle.startsWith("Freeze")){
freezeField(fieldNum);
//mycode
}else if(itemTitle.startsWith("Unfreeze")){
unfreezeField(fieldNum);
//mycode
}
}
});
/* This part is not working
if(itemTitle != null && itemTitle.startsWith("Group by") && item.getSubmenu() != null){
MenuItem[] subItems = item.getSubmenu().getItems();
if(subItems != null){
for (int j = 0; i < subItems.length; j++) {
final MenuItem subItem = subItems[i];
subItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
SC.say(subItem.getTitle());
}
});
}
}
}*/
}
return items;
}
I want to customize the header context menu by handling the onclick event of the menu items. I tried to override the getHeaderContextMenuItems method like below. But I am not able to retrieve the submenu items shown for Group by (by Day, by Week etc.) in case of date type field. Please help me with this.
protected MenuItem[] getHeaderContextMenuItems(final Integer fieldNum) {
MenuItem[] items = super.getHeaderContextMenuItems(fieldNum);
for (int i = 0; i < items.length; i++) {
final MenuItem item = items[i];
final String itemTitle = item.getTitle();
item.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
if("Sort Ascending".equals(itemTitle)){
sort(fieldNum, SortDirection.ASCENDING);
}else if("Sort Descending".equals(itemTitle)){
sort(fieldNum, SortDirection.DESCENDING);
}else if(item.getTitle().equals("Clear Sort")){
clearSort();
}else if(itemTitle.startsWith("Group by")){
groupBy(getFieldName(fieldNum));
//mycode
}else if(itemTitle.equals("Ungroup")){
ungroup();
//mycode
}else if(itemTitle.startsWith("Freeze")){
freezeField(fieldNum);
//mycode
}else if(itemTitle.startsWith("Unfreeze")){
unfreezeField(fieldNum);
//mycode
}
}
});
/* This part is not working
if(itemTitle != null && itemTitle.startsWith("Group by") && item.getSubmenu() != null){
MenuItem[] subItems = item.getSubmenu().getItems();
if(subItems != null){
for (int j = 0; i < subItems.length; j++) {
final MenuItem subItem = subItems[i];
subItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
SC.say(subItem.getTitle());
}
});
}
}
}*/
}
return items;
}
Comment