Announcement

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

    Grid CellContextClick Event doesn't work if parent component use sinkEvents(Event.ONCONTEXTMENU)

    Hi,

    Currently, we use the GXT framework. This framework use sinkEvents for prevent default context menu.
    We try to add the smartgwt grid in our gxt application.

    When the ListGrid is added in a gxt component CellContextClickHandler is never called. It's because in parent component, we prevent default context menu (it works fine if we don't prevent defaut menu).

    I reproduce the problem with only GWT and SmartGWT component:
    Code:
            public static ListGridRecord createRecord(String name, String surname) {
            ListGridRecord record = new ListGridRecord();
            record.setAttribute("Name", name);
            record.setAttribute("Surname", surname);
            return record;
        }
    
        public static ListGridRecord[] getRecords() {
            return new ListGridRecord[] {
                    createRecord("Name1", "Surname1"),
                    createRecord("Name2", "Surname2"),
                    createRecord("Name3", "Surname3")
            };
        }
    
    @Override
        public void onModuleLoad() {
            SimplePanel sp = new SimplePanel();
            sp.setSize("100%", "100%");
            sp.sinkEvents(Event.ONCONTEXTMENU);
            sp.addHandler(new ContextMenuHandler() {
    
                @Override
                public void onContextMenu(ContextMenuEvent event) {
                    event.preventDefault();
                }
            }, ContextMenuEvent.getType());
    
            final ListGrid grid = new ListGrid();
            grid.setWidth(500);
            grid.setHeight(300);
            grid.setData(getRecords());
    
            ListGridField nameField = new ListGridField("Name", "Name", 50);
            ListGridField surnameField = new ListGridField("Surname", "Surname");
    
            grid.setFields(nameField, surnameField);
    
            grid.addCellContextClickHandler(new CellContextClickHandler() {
    
                @Override
                public void onCellContextClick(CellContextClickEvent event) {
                    Menu menu = new Menu();
                    MenuItem hangupItem = new MenuItem("Hangup Call");
                    menu.addItem(hangupItem);
                    grid.setContextMenu(menu);
                }
            });
    
            sp.add(grid);
            RootPanel.get().add(sp);
        }
    If, i remove "event.preventDefault()" the context menu works.
    If i use "grid.sinkEvents(Event.ONCONTEXTMENU)" , i can catch grid right click but i don't know which cell has been clicked...

    Does anybody know how to catch CellContextClick (without sp.unsinkEvents(Event.ONCONTEXTMENU))?

    Thank you
Working...
X