Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Customized Header Context Menu

    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;
    }

    #2
    For one please use CODE tags when posting. Two why do you want to overrite those? And what exactly is the issue, that your click handler is never called?

    Comment


      #3
      I want to know when the state of the grid is changed like when group by column is changed or frozen columns have been changed. I want to save all these details so that I can re-construct the grid with same state.

      And in the code posted above. Following line is not working.
      item.getSubmenu().getItems();
      When I tried to debug, I found that getItems() method is throwing InvocationTargetException exception.

      Comment


        #4
        Yeah all that is considered internal and you're going to run into a lot of those issues, it isn't constructed like you think. Unforunately frozen fields and grouping isn't part of the state yet, but JSNI is your better bet to intercept the calls as opposed to overriding the menu.

        Comment

        Working...
        X