Cataclysm
Cataclysm

Reputation: 8548

GWT Alternative Cell

How to create GWT Cells alternatively at my Columns of Cell Table ?
For instance: I have one column and even rows will show Button Cells and odd rows will show Text Cells. Can it be possible ? If yes , how can I figure it out ? Thanks for any suggestions !

Below image is an example ....

enter image description here

Upvotes: 0

Views: 98

Answers (2)

Cataclysm
Cataclysm

Reputation: 8548

Thanks sir @AndreiVolgin. Now I got it. Here is my code as sir Andrei Volgin's answer.

        ButtonCell buttonCellEdit = new ButtonCell() {
        @Override
        public void render(final Context context, final SafeHtml data, final SafeHtmlBuilder sb) {
            if (i++ % 2 == 0) {
                sb.appendHtmlConstant("It is row " + i);
            }
            else {
                sb.appendHtmlConstant("<button type=\"button\" class=\"gwt-Button btn btnBlue\" tabindex=\"-1\">");
                if (data != null) {
                    sb.append(data);
                }
                sb.appendHtmlConstant("</button>");
            }
        }
    };

Upvotes: 0

Andrei Volgin
Andrei Volgin

Reputation: 41089

You can build a custom cell, which would render differently based on its context:

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    if (context.getIndex() & 1 == 0) {
        // render one way
    } else {
        // render the other way
    }
}

Upvotes: 2

Related Questions