I'm trying to create a component to configure the grid (sorting, filtering, pinning columns, and so on). Everything works well for standard speakers. I specify the number of frozen columns and they remain in place in any scenario. For columns that use Components Renderer, frozen columns are reset whenever the dataset changes (sorting by any column, filtering). If you freeze a regular column together with a column of components, the problem does not manifest itself.
I can't find any reasons for this behavior in my code. When the grid data is changed (for example, when sorting is set), the transform: translate3d(...) property of the element styles is simply reset for columns with the component.
I will be glad of any help or indication of the direction of the search.
Vaadin version 7.7.15, ComponentRenderer version 1.0.3.
The item SetChangeListener hangs on the container, which calls updateVisibleColumns (updates column data). The ComponentRenderer is installed here:
protected void updateVisibleColumns() {
if (dataSource == null) {
return;
}
final Collection<DataSourceColumn> visibleColumns = dataSource.getVisibleColumns();
setColumns(visibleColumns.toArray());
Map<String, ArrayList<Object>> groupMap = new HashMap<>();
for (final DataSourceColumn column : visibleColumns) {
if (column.getGroup() != null) {
if (!groupMap.containsKey(column.getGroup())) {
groupMap.put(column.getGroup(), new ArrayList<>());
}
groupMap.get(column.getGroup()).add(column);
}
final Column gridColumn = getColumn(column);
gridColumn.setHeaderCaption(column.getCaption());
if (column.getFormat() != null && !Component.class.isAssignableFrom(column.getType())) {
gridColumn.setConverter(new DataSourceColumnConverter(column));
}
if (Resource.class.isAssignableFrom(column.getType())) {
gridColumn.setRenderer(new ImageRenderer());
} else if (Component.class.isAssignableFrom(column.getType())) {
gridColumn.setRenderer(new ComponentRenderer());
}
}
recalculateColumnWidths();
}
In the example, a Label wrapped in VerticalLayout is used as a component to listen for clicks:
public class ClickableLabelField extends VerticalLayout implements Field<String>
Columns are frozen in a separate class to which a grid instance is passed. The frozen columns are installed in the setSettings method:
private final CheckBoxWithCaption fixFirstColumn
= new CheckBoxWithCaption("Закрепить первую колонку");
private final CheckBoxWithCaption severalFixColumn
= new CheckBoxWithCaption("Закрепить несколько колонок");
private final CheckBoxWithCaption showStripeRow
= new CheckBoxWithCaption("Отображать \"зебру\"");
public void setSettings() {
if (grid == null || grid.getColumns().isEmpty()) {
return;
}
if (Boolean.TRUE.equals(fixFirstColumn.getValue())) {
grid.setFrozenColumnCount(1);
} else if (Boolean.TRUE.equals(severalFixColumn.getValue())) {
Long fixColumn = getNumberColumnValue(columnNumberField.getValue());
if (fixColumn != null) {
grid.setFrozenColumnCount(fixColumn.intValue());
}
}
if (Boolean.TRUE.equals(showStripeRow.getValue())) {
grid.removeStyleName(EKPTheme.GRID_NO_STRIPE);
} else {
grid.addStyleName(EKPTheme.GRID_NO_STRIPE);
}
}