* Fix race condition between rendering Grid and setting up headers * Remove Grid default headers when initializing the widget * Fix header clean up, add null check to select all checkboxtags/8.1.0.alpha7
protected void init() { | protected void init() { | ||||
super.init(); | super.init(); | ||||
// Remove default headers when initializing Grid widget | |||||
while (getWidget().getHeaderRowCount() > 0) { | |||||
getWidget().removeHeaderRow(0); | |||||
} | |||||
registerRpc(GridClientRpc.class, new GridClientRpc() { | registerRpc(GridClientRpc.class, new GridClientRpc() { | ||||
@Override | @Override | ||||
*/ | */ | ||||
@OnStateChange("header") | @OnStateChange("header") | ||||
void updateHeader() { | void updateHeader() { | ||||
Scheduler.get().scheduleFinally(() -> { | |||||
final Grid<JsonObject> grid = getWidget(); | |||||
final SectionState state = getState().header; | |||||
while (grid.getHeaderRowCount() > 0) { | |||||
grid.removeHeaderRow(0); | |||||
} | |||||
final Grid<JsonObject> grid = getWidget(); | |||||
final SectionState state = getState().header; | |||||
for (RowState rowState : state.rows) { | |||||
HeaderRow row = grid.appendHeaderRow(); | |||||
while (grid.getHeaderRowCount() > 0) { | |||||
grid.removeHeaderRow(0); | |||||
} | |||||
if (rowState.defaultHeader) { | |||||
grid.setDefaultHeaderRow(row); | |||||
} | |||||
for (RowState rowState : state.rows) { | |||||
HeaderRow row = grid.appendHeaderRow(); | |||||
updateStaticRow(rowState, row); | |||||
if (rowState.defaultHeader) { | |||||
grid.setDefaultHeaderRow(row); | |||||
} | } | ||||
}); | |||||
updateStaticRow(rowState, row); | |||||
} | |||||
} | } | ||||
@OnStateChange("rowHeight") | @OnStateChange("rowHeight") |
* Sets the select all checkbox visible or hidden. | * Sets the select all checkbox visible or hidden. | ||||
*/ | */ | ||||
protected void doSetSelectAllCheckBoxVisible() { | protected void doSetSelectAllCheckBoxVisible() { | ||||
assert selectAllCheckBox != null : "Select All Checkbox has not been created for selection column."; | |||||
assert selectionCell != null : "Default header cell for selection column not been set."; | |||||
if (selectAllCheckBox == null || selectionCell == null) { | |||||
// There is no default header row to display select all checkbox | |||||
return; | |||||
} | |||||
if (selectAllCheckBoxVisible) { | if (selectAllCheckBoxVisible) { | ||||
selectionCell.setWidget(selectAllCheckBox); | selectionCell.setWidget(selectAllCheckBox); |
package com.vaadin.tests.components.treegrid; | |||||
import com.vaadin.annotations.Widgetset; | |||||
import com.vaadin.server.VaadinRequest; | |||||
import com.vaadin.tests.components.AbstractTestUI; | |||||
import com.vaadin.ui.Label; | |||||
import com.vaadin.ui.TreeGrid; | |||||
import com.vaadin.ui.renderers.ComponentRenderer; | |||||
@Widgetset("com.vaadin.DefaultWidgetSet") | |||||
public class TreeGridNoHeaderOnInit extends AbstractTestUI { | |||||
@Override | |||||
protected void setup(VaadinRequest request) { | |||||
TreeGrid<String> grid = new TreeGrid<>(); | |||||
grid.addColumn(Object::toString).setCaption("toString with Caption"); | |||||
grid.addColumn(t -> new Label(t), new ComponentRenderer()); | |||||
grid.setItems("Foo", "Bar", "Baz"); | |||||
grid.removeHeaderRow(0); | |||||
grid.appendFooterRow(); | |||||
addComponent(grid); | |||||
} | |||||
} |
package com.vaadin.tests.components.treegrid; | |||||
import org.junit.Test; | |||||
import com.vaadin.tests.tb3.SingleBrowserTest; | |||||
public class TreeGridNoHeaderOnInitTest extends SingleBrowserTest { | |||||
@Test | |||||
public void no_exception_thrown() { | |||||
setDebug(true); | |||||
openTestURL(); | |||||
assertNoErrorNotifications(); | |||||
} | |||||
} |