2 Replies Latest reply on Apr 1, 2010 4:14 AM by ilya_shaikovsky

    How to create dynamic datatable with dynamic column group?

    littlealan

      Hi,

       

      I'd like to create a datatable with dynamic columns with dynamic columngroup like attached image.

       

      columngroup.jpg

       

      The columns are dynamic retrieved from DB. And the ordering of the column groups are also dynamic.

       

      E.g. If the first column group is "Conveyance", then both "carrier" and "vessel/voyage" columns are placed as the first columns under the "conveyance" group.

       

      How to achieve this? In the document mentioned can use the colSpan/rowSpan/insertBefore with rich:columns, but if i try this:

       

               <rich:columns value="#{dataTableScrollerBean.columns2}" var="columns"
                      index="ind" id="column#{ind}" rowspan="2"...>

       

      Then all the columns are spanned 2 rows. which is not the expected result.

       

      And I tried to do it programmatically,

       

      public void initColumnsHeaders2() {
              columns2.clear();
              HtmlColumn column = new HtmlColumn();
              //import org.richfaces.component.html.HtmlColumn;
              HtmlOutputText header = new HtmlOutputText();
              header.setValue("Chevrolet");
              column.setHeader(header);
              columns2.add(column);
              column = new HtmlColumn();
              header = new HtmlOutputText();
              header.setValue("Ford");
              column.setHeader(header);
              columns2.add(column);

       

      But it seems cannot read the HtmlOutputText as the header facet properly as below:

      columngroup2.jpg

       

      I'm using richfaces 3.3.2.SR1. Please help!

       

      Alan

        • 1. Re: How to create dynamic datatable with dynamic column group?
          littlealan

          I also tried in the demo example, add the rowspan and colspan in the Facet class, see if the rich:columns can pick the attributes up:

           

          public class Facet {
              private String header;
              private String footer;
              private int rowspan;
              private int colspan;

          }

           

          //In DataTableScrollerBean

          public void initColumnsHeaders() {
                  columns.clear();
                  String header;
                  String footer = "";
                  header = "Chevrolet";
                  Facet facet = new Facet(header, footer);
                  facet.setRowspan(2);
                  columns.add(facet);

          }

           

                   <rich:columns value="#{dataTableScrollerBean.columns}" var="columns"
                          index="ind" id="column#{ind}" sortBy="#{model[ind].price}" sortOrder="#{columns.sortOrder}">

           

          But still not works. It just ignore the rowspan attributes. Please help.

          • 2. Re: How to create dynamic datatable with dynamic column group?
            ilya_shaikovsky

            It ignores rowSpan attribute as it should be defined at column tags. And you just defines it in some object about columns just not care. for columns like: rowSpan="#{column.spanValue}" where column is var variable of rich:columns.