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; }
/** * Setter method for Layout property. This property allows an application to control the * position of the splitter bar and ordering of columns. * * @param layout The layout data. */ public void setLayout(String layout) { String[] pcs = StrUtil.split(layout, ";"); if (pcs.length > 0) { String[] spl = StrUtil.split(pcs[0], ":", 3); sortColumn = NumberUtils.toInt(spl[1]); sortAscending = BooleanUtils.toBoolean(spl[2]); } for (int i = 1; i < pcs.length; i++) { String[] col = StrUtil.split(pcs[i], ":", 2); Column lhdr = getColumnByIndex(NumberUtils.toInt(col[0])); if (lhdr != null) { lhdr.setWidth(col[1]); lhdr.setIndex(i - 1); } } doSort(); }