Thursday, March 21, 2013

Dynamically Calculate Grid Height in GWT


final Grid gwtGrid = new Grid(statusStore, columnModel);
gwtGrid.setView(groupView);
gwtGrid.setBorders(true);
gwtGrid.setColumnLines(true);
gwtGrid.setColumnResize(false);
gwtGrid.getView().setForceFit(true);
statusStore.add(result);
gwtGrid.enable();
gwtGrid.getView().setFiresEvents(true);

final Listener lsnr = new Listener() {

@Override
public void handleEvent(BaseEvent be) {
int panelHeader = 30;
int gridHeight = 0;
int gridHeader = gwtGrid.el().selectNode(".x-grid3").getHeight();
NodeList rowsNodes = gwtGrid.el().select(".x-grid3-row");
for (int i = 0; i < rowsNodes.getLength(); i++) {
gridHeight += rowsNodes.getItem(i).getOffsetHeight();
}
gridHeight += panelHeader + gridHeader + 20;
//Window.alert(String.valueOf(gridHeight));
mainContentPanel.setHeight(gridHeight + 10);

pageHeight = pageHeight + gridHeight;

QNBClassic.getClassicMainPanel().setSize(995, pageHeight);
QNBClassic.getTabPanel().setSize(995, pageHeight);
}
};
gwtGrid.addListener(Events.ViewReady, lsnr);

No comments: