Search code examples
gwtsmartgwt

Give the delete button a confirmation prompt


Is there a way to give the user a prompt window popup when clicking the remove field button?

enabling the remove button :

setCanRemoveRecords(true);

enter image description here

When I click the red remove button, I want a confirmation box ask me if I want to delete it, yes or no. What should I use to bring that up?

Should I be adding something into

  @Override
    public void removeData(Record group)
    {
        ...
    }

Solution

  • Here are the options:

    • Use addCellClickHandler on ListGrid and perform operation based on cell no
    • Add addRecordClickHandler on ListGridField itself that is used for delete icon

    I prefer last option.

    Sample code:

        final ListGrid countryGrid = new ListGrid();
        ...
    
        countryGrid.setWarnOnRemoval(true);
    
        countryGrid.setCanRemoveRecords(true);
        ListGridField ls = new ListGridField();
        countryGrid.setRemoveFieldProperties(ls);
        ls.setHoverCustomizer(new HoverCustomizer() {
    
            @Override
            public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
                // System.out.println(colNum);
                return "click here to delete this record";
            }
        });
    
        ls.addRecordClickHandler(new RecordClickHandler() {
    
            @Override
            public void onRecordClick(final RecordClickEvent event) {
                SC.confirm("Are you sure?", new BooleanCallback() {
    
                    @Override
                    public void execute(Boolean value) {
                        if (value == null || !value) {
                            event.cancel();
                        }
                    }
                });
    
            }
        });
    
        /*countryGrid.addCellClickHandler(new CellClickHandler() {
    
            @Override
            public void onCellClick(final CellClickEvent event) {
                // column number having delete icon
                // System.out.println(event.getColNum());
                if (event.getColNum() == 3) {
                    SC.confirm("Are you sure", new BooleanCallback() {
    
                        @Override
                        public void execute(Boolean value) {
                            if (value == null || !value) {
                                event.cancel();
                            }
                        }
                    });
                }
            }
        });*/