Someone gave an example of making text content wrap in table, also remove horizontal scroll bar. Link is here. My tested code here:
table.setHeight("100%");
table.setWidth("100%");
table.setPageLength(0);
table.setColumnWidth("title", 55);
table.setColumnExpandRatio("description", 1);
table.setContainerDataSource(new BeanItemContainer<Person>(createTestData()));
table.setVisibleColumns(new String[] { "name", "description" });
// Insert your own theme rules here
.v-table-cell-wrapper {
white-space: normal;
}
<!-- Comment out compile-theme goal to use on-the-fly theme compilation -->
<!-- <goal>compile-theme</goal> -->
It seems the most important part is:
table.setWidth() sets table width, for example, 100%
This sets the width to hold the columns. However, setting table width does not guarantee the actual contents (that is, all columns) be that size. When all columns exceeds the table width, slide bar appears (which many does not like). When not enough to fill table width, a gap appears.
If initially column expansion is set, then the columns will fill exactly the table width, and in fact the columns will adjust as table width (actual width) changes - for example table is in a horizontal split panel.
However if user drags to adjust width of a column, the automatic adjustment is broken (table does not know what to do).
To solve this, either disable column resize, or make it smart.
To disable column resize, one way is to addColumnResizeListener and just reset the sizes. (so override user adjusement).
Another way, someone mentioned to set the resizer element on page to not display (so effectively prevent people from dragging it). Example as follows, it may depend on the theme. Have not tried yet.
.i-table-resizer {
width: 0px !important;
}
or
.i-table-resizer {
display: none;
}
Below works, but only cells are changed (table header not).
public static class ColumnHighlighter implements CellStyleGenerator {
Integer pid;
public ColumnHighlighter(Integer id){
pid = id;
}
@Override
public String getStyle(Table source, Object itemId, Object propertyId) {
if (propertyId instanceof Integer && propertyId.equals(pid)) {
return "cellhighlight";
}
return null;
}
}
...... t.setCellStyleGenerator(new ColumnHighlighter(colId));
Note CSS should be:
.v-table-cell-content-cellhighlight {
background-color: yellow;
}
Also someone mentioned how to highlight table header cell here, and it works:
.v-table-header-cell:nth-child(2) {
background : red;
}
book - "Alternatively, you can use a Table.ColumnGenerator (see Generated Table Columns) to generate the actual UI components of the cells and add style names to them."