给删除按钮一个确认提示

时间:2014-03-24 19:06:00

标签: gwt smartgwt

点击删除字段按钮有没有办法让用户弹出提示窗口?

启用删除按钮:

setCanRemoveRecords(true);

enter image description here

当我点击红色删除按钮时,我想要一个确认框询问我是否要删除它,是或否。我该怎么用才能搞清楚?

我应该在

中添加内容吗?
  @Override
    public void removeData(Record group)
    {
        ...
    }

2 个答案:

答案 0 :(得分:1)

您可以使用以下方法:

ListGrid#setWarnOnRemoval用于显示警告消息和

ListGrid#setWarnOnRemovalMessage用于设置自定义消息。

Refer documentation.

答案 1 :(得分:1)

以下是选项:

  • addCellClickHandler上使用ListGrid并根据单元格号
  • 执行操作
  • 在用于删除图标的addRecordClickHandler本身上添加ListGridField

我更喜欢上一个选项。

示例代码:

    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();
                        }
                    }
                });
            }
        }
    });*/