protected void setup(String title, int sortBy, String... headers) { setCaption(title); dataName = title; String defWidth = (100 / headers.length) + "%"; for (String header : headers) { String[] pcs = StrUtil.split(header, "^", 3); Column lhdr = new Column(pcs[0]); columns.addChild(lhdr); lhdr.setAttribute(SORT_TYPE_ATTR, NumberUtils.toInt(pcs[1])); lhdr.setAttribute(COL_INDEX_ATTR, colCount++); String width = pcs[2]; if (!width.isEmpty()) { if (NumberUtils.isDigits(width) || "min".equals(width)) { //lhdr.setHflex(width); } else { lhdr.setWidth(width); } } else { lhdr.setWidth(defWidth); } } sortColumn = Math.abs(sortBy) - 1; sortAscending = sortBy > 0; doSort(); }
/** * Adds a column to a grid. * * @param grid Grid. * @param label Label for column. * @param width Width for column. * @param sortBy Field for sorting. * @return Newly created column. */ public Column addColumn(Grid grid, String label, String width, String sortBy) { Column column = new Column(); grid.getColumns().addChild(column); column.setLabel(label); column.setWidth(width); column.setSortComparator(sortBy); column.setSortOrder(SortOrder.ASCENDING); return column; }