繁体   English   中英

GWT Button下拉列表在子表的单元格事件处理中

[英]Gwt Button dropdown in celltable event handling on children

我的表格中有太多按钮,我想用一个可以打开下拉列表的按钮来代替它们。 但是我真的不知道如何处理下拉菜单中的事件。 我设法使用javascript函数来做到这一点,但这不是很实用,因为我只能传递原始值。

我还希望将来将其作为自定义单元,以在项目的不同页面中使用它,因此返回一些html不太实用。

这是我的代码:

     final ButtonCell buttonInfoCell = new ButtonCell();
         Column<GwtStockProduct, String> buttonCell = new Column<GwtStockProduct, String>(buttonInfoCell) {

     @Override
     public void render(final Context context, final GwtStockProduct value, final SafeHtmlBuilder sb) {
     Div div = new Div();
     Div bG = new Div();
     div.add(bG);
     bG.addStyleName("btn-group");

     Button button = new Button();
     DropDownMenu dropDown = new DropDownMenu();

     Span span = new Span();
     span.addStyleName("caret");
     span.setVisible(false);
     button.add(span);

     button.getElement().setAttribute("style", "background-image: none !important; background-color: #234C78 !important;");
     // button.removeStyleName("");
     button.addStyleName("btn-hide-icon btn-blue");
     button.setDataToggle(Toggle.DROPDOWN);
     button.setText("Change stock");

     for (int i = 1; i < 5; ++i) {
     AnchorListItem item = new AnchorListItem();
     item.getElement().getFirstChildElement().removeAttribute("href");
     item.getElement().getFirstChildElement().setAttribute("onclick", "triggerClick('" + i + "')");
     item.setText("Item " + i);
     dropDown.add(item);
     }

     // dropDown.getElement().setAttribute("style", "position: relative !important;");
     bG.add(button);
     bG.add(dropDown);

     // sb.append(SafeHtmlUtils.fromTrustedString(buttonGroup));
     sb.appendHtmlConstant(div.getElement().getInnerHTML());
     }

     @Override
     public String getValue(final GwtStockProduct object) {
     // TODO Auto-generated method stub
     return null;
     }
     };

     stockTable.addColumn(buttonCell, "Actions");
     stockTable.setColumnWidth(buttonCell, 5, Unit.PCT);

我使用SelectionCell渲染选项的下拉列表。 也许会帮助您:

ArrayList<String> options = new ArrayList<String>();
options.add("choose an option..."); // the prompt text
options.add("option 1");
options.add("option 2");
// ...

final SelectionCell optionsCell = new SelectionCell(options);

Column<TableType, String> optionsColumn = new Column<TableType, String>(optionsCell) {
    @Override
    public String getValue(TableType object) {
        return null;
    }
};
optionsColumn.setFieldUpdater(new FieldUpdater<TableType, String>() {
    @Override
    public void update(int index, TableType object, String value) {
        if(value == "option 1")
            // process option 1
        else if(value == "option 2")
            // process option 2
        // ...

        // reset drop-down to show the prompt text
        optionsCell.clearViewData(object);
        redrawRow(index);
    }
});

table.addColumn(optionsColumn, "options");

第一个选项只是提示文本,在每次选择更改后,都会重置下拉列表以显示提示。

缺点是您不能为不同的行使用不同的选项集,因为整个列只生成一次列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM