Search code examples
javagwtgxt

Put widget inside RowExpander in GXT


Is there a way to display widget in the expanded area? RowExpander uses AbstractCell which can display only simple html. It is possible to take html from widget and place it into cell but the buttons in the widget won't work after this.


Solution

  • Extend the RowExpander class and/or override the method beforeExpand. Here's what I did and it works great for inserting a button or in my case i needed a grid:

    public class RowWidgetExpander extends RowExpander {
    
    private Widget widget;
    
    public void setWidget(Widget widget) {
        this.widget = widget;
    }
    
    public Widget getWidget() {
        return widget;
    }
    
    @Override
    protected boolean beforeExpand(ModelData model, Element body, El row, int rowIndex) {
        RowExpanderEvent e = new RowExpanderEvent(this);
        e.setModel(model);
        e.setRowIndex(rowIndex);
        e.setBodyElement(body);
    
        if(fireEvent(Events.BeforeExpand, e)) {
            body.setInnerText("");
            body.appendChild(widget.getElement());
            ComponentHelper.doAttach(widget);
    
            return true;
        }
    
        return false;
    }