17

I have a case where I want to append

white-space: nowrap;

to the style of each cell in my CellTable. Currently it applies to all tables, but it would be nice to know both have to apply it for a specific CellTable, and all CellTables.

l3dx
  • 2,930
  • 6
  • 33
  • 43

2 Answers2

31

CellTables have their own CssResource. To override this style applied to all cells in a cellTable, create a new css file :

/* Incremental changes from CellTable.css */ 
.cellTableCell {
  white-space: nowrap;
}

Then create your own CellTable.Resources interface :

public interface TableResources extends CellTable.Resources {

    /**
       * The styles applied to the table.
       */
    interface TableStyle extends CellTable.Style {
    }

    @Override
    @Source({ CellTable.Style.DEFAULT_CSS, "MyOwnCellTableStyleSheet.css" })
    TableStyle cellTableStyle();

}

Finally, when creating your cellTable, use the constructor that lets you specify which Resources to use

CellTable<Object> myCellTable = new CellTable<Object>(15, GWT.create(TableResources.class));

For a working example, look at the Expenses sample provided in the GWT SDK.

jonasr
  • 1,876
  • 16
  • 18
  • 3
    Very nice answer, worked well with me, except that on GWT 2.4 you have to cast to Resources like (Resources)GWT.create(TableResources.class) to work. – george_h Jul 27 '12 at 08:49
  • Thanks for the solution. I found out that it also works without the TableStyle interface altogether. You can just write: CellTable.Style cellTableStyle(); This reduces the boilerplate somewhat. I tried it on GWT 2.6.0 – dexter Nov 07 '14 at 09:36
0

Or you could do this the easy way:

CellTable<YourObj> yourTable = new CellTable<YourObj>();
yourTable.getElement().getStyle().setWhiteSpace(WhiteSpace.NOWRAP);

No css files, no weird boilerplate code.

Robert
  • 1,220
  • 16
  • 19