0

我尝试将按钮添加到 rowExpander 内容中:所以我有:

ButtonCell<Integer> viewButtonCell = new ButtonCell<Integer>();

和行扩展器

RowExpander<XX> expander = new RowExpander<XX>(identity, new AbstractCell<XX>() {
        @Override
        public void render(Context context, XX value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<span>");
            viewButtonCell.render(context, value.getId(), sb);
            sb.appendHtmlConstant("</span>");
        }

ButtonCell 渲染好我可以看到它但我无法单击它,没有调用 ButtonCell 的 selecthandler :(。有什么想法可以让这个按钮 selectHandlerActive 吗?

谢谢

4

1 回答 1

0

我创建了一些新的 RowExpander :

public class MTPRowExpander<M> extends RowExpander<M> {

    public static int id = 0;

    public static interface WidgetFactory<M> {
        public Widget createWidget(M model);
    }

    private WidgetFactory<M> wf;
    private Set<Integer> expandedRows;

    public MTPRowExpander(IdentityValueProvider<M> valueProvider,WidgetFactory<M> wf) {
        this(valueProvider,GWT.<RowExpanderAppearance<M>> create(RowExpanderAppearance.class),wf);
    }

    public MTPRowExpander(IdentityValueProvider<M> valueProvider,final RowExpanderAppearance<M> appearance, WidgetFactory<M> wf) {
        super(valueProvider, null, appearance);
        this.wf = wf;
        expandedRows = new HashSet<Integer>();
    }

    @Override
    protected boolean beforeExpand(M model, Element body, XElement row,int rowIndex) {
        if (expandedRows.contains(rowIndex)) {
            return true;
        } else {
            expandedRows.add(rowIndex);
            return super.beforeExpand(model, body, row, rowIndex);
        }
    }

    @Override
    protected String getBodyContent(final M model, int rowIndex) {
        final int curentid = id++;
        Scheduler.get().scheduleFinally(new ScheduledCommand() {
            @Override
            public void execute() {
                Widget widget = wf.createWidget(model);
                com.google.gwt.dom.client.Element item = grid.getElement().childElement(".widget" + curentid);
                item.appendChild(widget.getElement());
                ComponentHelper.setParent(grid, widget);
            }
        });
        return "<div class='widget" + curentid + "'></div>";
    }

}

我知道这个解决方案并不完美,但我不知道如何以更合适的方式解决问题。

于 2013-11-08T11:46:44.750 回答