4 Replies Latest reply on Nov 10, 2008 11:50 AM by Ilya Shaikovsky

    sort in dynamic table

    igal israilevich Newbie

      Hi all,

      I have problems with sorting and filtering table that I've created using java code. That is I get headers like in demo but clicking on the headers doesn't do nothing.

      Here my code:

      private void populateDynamicDataTable() {

      // Create <h:dataTable binding="#{displayList.dynamicDataTable}"
      // value="#{displayList.dynamicList}" var="dynamicItem">.
      HtmlDataTable dynamicDataTable = new HtmlDataTable();
      dynamicDataTable.setValueExpression("binding", FacesUtils.createValueExpression("#{displayList.dynamicDataTable}", HtmlDataTable.class));
      dynamicDataTable.setValueExpression("value", FacesUtils.createValueExpression("#{displayList.dynamicList}", List.class));
      dynamicDataTable.setVar("dynamicItem");
      dynamicDataTable.setId("simpletable");
      dynamicDataTable.setReRender("ds");
      dynamicDataTable.setRows(5);

      // Iterate over columns.
      for (int i = 0; i < dynamicHeaders.length; i++) {

      HtmlColumn column = new HtmlColumn();
      column.setId("col" + i);
      column.setValueExpression("sortBy",FacesUtils.createValueExpression("#{dynamicHeaders["+ i +"]}", String.class) );
      dynamicDataTable.getChildren().add(column);
      // Create <h:outputText value="dynamicHeaders"> for <f:facet name="header"> of column.
      HtmlOutputText header = new HtmlOutputText();
      header.setValue(dynamicHeaders
      );
      header.setTitle("m" + i);
      column.setHeader(header);

      // Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the body of column.
      HtmlOutputText output = new HtmlOutputText();
      output.setValueExpression("value", FacesUtils.createValueExpression("#{dynamicItem[" + i + "]}", String.class));
      column.getChildren().add(output);
      }
      // <rich:datascroller id="ds"></rich:datascroller>
      HtmlDatascroller footer = new HtmlDatascroller();
      footer.setId("ds");
      dynamicDataTable.setFooter(footer);


      // Add the datatable to <h:panelGroup binding="#{myBean.dynamicDataTableGroup}">.
      dynamicDataTableGroup = new HtmlPanelGroup();
      dynamicDataTableGroup.getChildren().add(dynamicDataTable);

      }