/** * Paints the column headings for the given table. * * @param table the table to paint the headings for. * @param renderContext the RenderContext to paint to. */ private void paintColumnHeadings(final WTable table, final WebXmlRenderContext renderContext) { XmlStringBuilder xml = renderContext.getWriter(); int[] columnOrder = table.getColumnOrder(); TableModel model = table.getTableModel(); final int columnCount = columnOrder == null ? table.getColumnCount() : columnOrder.length; xml.appendTagOpen("ui:thead"); xml.appendOptionalAttribute("hidden", !table.isShowColumnHeaders(), "true"); xml.appendClose(); for (int i = 0; i < columnCount; i++) { int colIndex = columnOrder == null ? i : columnOrder[i]; WTableColumn col = table.getColumn(colIndex); if (col.isVisible()) { boolean sortable = model.isSortable(colIndex); paintColumnHeading(col, sortable, renderContext); } } xml.appendEndTag("ui:thead"); }
/** * Indicates whether the table supports sorting. * * @return true if the table and model both support sorting, false otherwise. */ public boolean isSortable() { // First check global override which turns sorting off if (getSortMode() == SortMode.NONE) { return false; } // Otherwise, the table is sortable if at least one column is sortable. TableModel dataModel = getTableModel(); final int columnCount = getColumnCount(); for (int i = 0; i < columnCount; i++) { if (dataModel.isSortable(i)) { return true; } } return false; }