tbody.<XElement> cast().removeChildren();
DomHelper.insertHtml("afterBegin", tbody, renderHiddenHeaders(getColumnWidths()).asString());
List<HeaderGroupConfig> configs = cm.getHeaderGroups();
FlexCellFormatter cf = table.getFlexCellFormatter();
RowFormatter rf = table.getRowFormatter();
rows = 0;
for (HeaderGroupConfig config : configs) {
rows = Math.max(rows, config.getRow() + 1);
}
rows++;
for (int i = 0; i < rows; i++) {
rf.setStyleName(i, styles.headRow());
}
int cols = cm.getColumnCount();
String cellClass = styles.header() + " " + styles.head();
if (rows > 1) {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int i = 0; i < rows - 1; i++) {
for (HeaderGroupConfig config : cm.getHeaderGroups()) {
int col = config.getColumn();
int row = config.getRow();
Integer start = map.get(row);
if (start == null || col < start) {
map.put(row, col);
}
}
}
}
for (HeaderGroupConfig config : cm.getHeaderGroups()) {
int col = config.getColumn();
int row = config.getRow();
int rs = config.getRowspan();
int cs = config.getColspan();
Group group = createNewGroup(config);
boolean hide = true;
if (rows > 1) {
for (int i = col; i < (col + cs); i++) {
if (!cm.isHidden(i)) {
hide = false;
}
}
}
if (hide) {
continue;
}
table.setWidget(row, col, group);
cf.setStyleName(row, col, cellClass);
HorizontalAlignmentConstant align = config.getHorizontalAlignment();
cf.setHorizontalAlignment(row, col, align);
int ncs = cs;
if (cs > 1) {
for (int i = col; i < (col + cs); i++) {
if (cm.isHidden(i)) {
ncs -= 1;
}
}
}
cf.setRowSpan(row, col, rs);
cf.setColSpan(row, col, ncs);
}
for (int i = 0; i < cols; i++) {
Head h = createNewHead(cm.getColumn(i));
if (cm.isHidden(i)) {
continue;
}
int rowspan = 1;
if (rows > 1) {
for (int j = rows - 2; j >= 0; j--) {
if (!cm.hasGroup(j, i)) {
rowspan += 1;
}
}
}
int row;
if (rowspan > 1) {
row = (rows - 1) - (rowspan - 1);
} else {
row = rows - 1;
}
h.row = row;
if (rowspan > 1) {
table.setWidget(row, i, h);
table.getFlexCellFormatter().setRowSpan(row, i, rowspan);
} else {
table.setWidget(row, i, h);
}
ColumnConfig<M, ?> cc = cm.getColumn(i);
String s = cc.getCellClassName() == null ? "" : " " + cc.getCellClassName();
cf.setStyleName(row, i, cellClass + s);
cf.getElement(row, i).setPropertyInt("gridColumnIndex", i);
HorizontalAlignmentConstant align = cm.getColumnAlignment(i);
if (align != null) {
table.getCellFormatter().setHorizontalAlignment(row, i, align);
if (align == HasHorizontalAlignment.ALIGN_RIGHT) {