4 Replies Latest reply on Apr 27, 2012 11:37 AM by Mohsin Khan

    DataTable sorting does not work when creating the DataTable

    Ganesh Rao Newbie

      I am having trouble in getting sorting to work when I create the HTMLDatatable programmatically. The table gets rendered just fine. The part that is not working is that the header is not clickable. The two icons are missing for each header. If I switch from this approach to listing all columns in the JSF using rich:column everything works!.

      Any help is appreciated.

      Facelets page
      The JSF component is accessing the outjected DataTable

      <ui:composition xmlns:jsp="http://java.sun.com/JSP/Page"
       xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:c="http://java.sun.com/jstl/core"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:aries="http://rd.gsk.com/aries/widget">
      
       <rich:dataTable
       id="subjectGroups"
       rowClasses="row-highlight, row-normal"
       binding="#{subjectGroupsDataTable}"/>
      
      </ui:composition>
      

      Method in my seam component that generates the HTMLDataTable instance
      HtmlDataTable dataTable = new HtmlDataTable();
       dataTable.setId(id);
       dataTable.setValueExpression("value",
       createValueExpression("#{" + valueExpression + ".rows}", List.class));
       dataTable.setVar("record");
       if (tableModel != null) {
       List<HtmlColumn> columns = new ArrayList<HtmlColumn>();
       int index = 0;
       for (SmartTableColumn smartColumn : tableModel.getColumns()) {
      
       // Create column.
       HtmlColumn column = new HtmlColumn();
       column.setSelfSorted(true);
       // Create output and add to column.
       UIComponent output = null;
       HtmlOutputText header = new HtmlOutputText();
       header.setValue(smartColumn.getColumnHeader());
       column.setHeader(header);
       output = new HtmlOutputText();
       output.setValueExpression("value", createValueExpression("#{record." + smartColumn.getBeanAttribute() + "}", String.class));
       column.setSortBy("#{record." + smartColumn.getBeanAttribute() + "}");
      
       column.setId("header" + index);
       index++;
       column.getChildren().add(output);
      
      
       // Add column to datatable.
       columns.add(column);
       dataTable.getChildren().add(column);
       }
       }
       return dataTable;