How to add a css class to the first column of a CellTable widget (GWT)?

623 views Asked by At

I use a CellTable widget in GWT.

I want to change the font size of every texts contained in the first column. The method addColumnStyleName does not fit my need because it adds the class to the colgroup tag; only partial css is handled on this tag, and I can't change the font attributes of a colgroup (it has no incidence on text).

So, I want to add a class on each td of the first column but cannot find an easy way to do that.

Something like setRowStyles for columns would be fine but it doesn't exist...

Have you got some hint about doing such a thing ?

EDIT: I use GWT 2.3 and not 2.4 (which has the method setCellStyleNames)

2

There are 2 answers

3
Thomas Broyer On BEST ANSWER

It's as easy as calling setCellStyleNames on the Column instance.

1
Jerome Cance On

I finally get it. But I'm not really happy with that solution. It's a bit verbose for a such simple task. I'm opened to any other suggestion.

The way I achieve it is to create a new cell and a new column :

private class KeyColumn extends Column<SimpleLegendItem, String> {

    public KeyColumn() {
        super(new KeyCell());
    }

    @Override
    public String getValue(SimpleLegendItem item) {
        return item.getKey();
    }       
}

private class KeyCell extends AbstractCell<String> {

    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
        sb.appendHtmlConstant("<span class=\"" + tableResources.cellTableStyle().box() + "\">");
        sb.appendEscaped(value);
        sb.appendHtmlConstant("</span>");
    }       
}

To simplify the example, I intentionally do not use a template.