我正在尝试在Vaadin框架的网格组件内显示项目列表。默认情况下,网格的尺寸很小。它没有显示所有列名。我需要滚动查看所有列。我的网格只有10列。它不会根据列表中的数据进行更改。
我尝试通过以下方法设置网格的大小:
this.grid.setHeightByRows(list.size());
this.grid.setSizeUndefined();
this.grid.setSizeFull();
以上均不能根据数据设置大小
private Grid<PrevYearConsumption> createGridTable() {
Grid<PrevYearConsumption> grid = new Grid<PrevYearConsumption>();
grid.addColumn(PrevYearConsumption::getPreviousPeriod).setCaption(PrevYearConstants.PREVIOUS_PERIOD);
grid.addColumn(PrevYearConsumption::getPresentReading).setCaption("Prev Elec");
grid.addColumn(PrevYearConsumption::getPreviousDataComplete)
.setCaption(PrevYearConstants.PREVIOUS_DATA_COMPLETE);
grid.addColumn(PrevYearConsumption::getPreviousDq).setCaption(PrevYearConstants.PREVIOUS_DQ);
grid.addColumn(PrevYearConsumption::getPresentPeriod).setCaption(PrevYearConstants.PRESENT_PERIOD);
grid.addColumn(PrevYearConsumption::getPresentReading).setCaption("Present Elec");
grid.addColumn(PrevYearConsumption::getPresentDataComplete).setCaption(PrevYearConstants.PRESENT_DATA_COMPLETE);
grid.addColumn(PrevYearConsumption::getPresentDq).setCaption(PrevYearConstants.PRESENT_DQ);
grid.addColumn(PrevYearConsumption::getDiff).setCaption(PrevYearConstants.DIFFERENCE);
grid.addColumn(PrevYearConsumption::getPercentageChange).setCaption(PrevYearConstants.PERCENTAGE);
grid.setSizeUndefined();
return grid;
}
在View类内部
public class viewClass {
private HorizontalLayout tableLayout = new HorizontalLayout();
public void method ()
{
this.grid = createGridTable();
this.tableLayout.setSizeFull();
this.tableLayout.addComponent(this.grid);
List<PrevYearConsumption> list = getList();
this.grid.setItems(list);
}
}
使用此:
this.tableLayout.setSizeUndefined();