Announcement

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

    Adding items to default contextMenu in ListGrid

    I would like to add a few items to the headerContextMenu in the ListGrid.

    I know that getHeaderContextMenu(fieldnum) is used to populate the default items. What would be the correct method for extending this list?

    A short example would be greatly appreciated.

    Thanks,
    paul

    #2
    Here is an example that works for me. I wanted to add a menu item separator followed by an option to download the grid contents as a csv file.
    Code:
    private final ListGrid itemGrid = new ListGrid()        
    // add a "download to Excel" option to the standard grid header menu
    {
       protected MenuItem[] getHeaderContextMenuItems(final Integer fieldNum) {
           final MenuItem[] items = super.getHeaderContextMenuItems(fieldNum);
           MenuItem customItem = new MenuItem("Download to Excel");
           customItem.setIcon("../customimages/excel.png");
           customItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
               public void onClick(MenuItemClickEvent event) {
                   exportData();       
               }
           });
           MenuItem[] newItems = new MenuItem[items.length + 2];
           for (int i = 0; i < items.length; i++) {
               MenuItem item = items[i];
               newItems[i] = item;
           }
           newItems[items.length] = new MenuItemSeparator();
           newItems[items.length+1] = customItem;
           return newItems;
        }
    };

    Comment


      #3
      Thanks Jay.

      I was able to translate this general method to .js easily enough.

      Comment

      Working...
      X