5 Replies Latest reply on Aug 25, 2009 5:13 AM by Jonh smith

    rich:datatable and sorting (data table)

    Jonh smith Newbie
      I want to have this table with column1 and column2 sorting by richfaces, but the sorting  do not appear.

      Can someone help? Thanks.

      column1     | column2  |               column3               |
      value1   |    value2  |     s1   |       s2       |  s3     |
      value1   |    value2  |     s1   |       s2       |  s3     |
      value1   |    value2  |     s1   |       s2       |  s3     |
      value1   |    value2  |     s1   |       s2       |  s3     |
      value1   |    value2  |     s1   |       s2       |  s3     |
      value1   |    value2  |     s1   |       s2       |  s3     |

      My code is:

              <rich:dataTable id="table" var="record"
                  value="#{tableBean.values}" rows="10" width="100%">
               <f:facet name="header">
           
                   <rich:columnGroup>             
                        <rich:column>                  
                         <h:outputText value="Column1" />                  
                        </rich:column>
                        
                        <rich:column>                  
                         <h:outputText value="Column2" />                   
                        </rich:column>            
                   
                        <rich:column colspan="3">                  
                        <h:outputText value="Column3" />                  
                         </rich:column>
                   
                   </rich:columnGroup>
                </f:facet>
           
             <rich:column sortBy="record.value1">
             <h:outputText value="record.value1" />
             </rich:column>
                   
                   
             <rich:column>
             <h:outputText value="record.value2" />
             </rich:column>
            
              <rich:column>
             <h:outputText value="record.s1" />
             </rich:column>
            
              <rich:column>
             <h:outputText value="record.s2" />
             </rich:column>
            
             <rich:column>
             <h:outputText value="record.s3" />
             </rich:column>
      </rich:dataTable>

      Can someone help? Thanks.
        • 1. Re: rich:datatable and sorting (data table)
          Tim Evers Master

          Take a look at the doco for a rich:dataTable
          rich:dataTable Doco


          As a standalone component the rich:dataTable does not offer sorting. There are two ways you could add sorting.
          Change your headers to be links then make the click on the link do the sorting for you in an action method in your SEAM bean. Alternativly have a look at the rich:extendedDataTable component. This component offers sorting out of the box. You will need to read the rich:extendedDataTable Doco though to get it working. It can be a litte tricky at first.

          • 2. Re: rich:datatable and sorting (data table)
            Jonh smith Newbie
            The dafaul component rich:dataTable does offer sorting. I did that with this code:

              <rich:dataTable id="table" var="record"
                        value="#{tableBean.values}" rows="10" width="100%">
                    
                     <rich:columnGroup>
                        <rich:column sortBy="record.value1">
                             <f:facet name="header">  
                                 <h:outputText value="Column1" />
                             </f:facet>
                         <h:outputText value="record.value1"/>
                        </rich:column>
                        <rich:column sortBy="record.value2">
                              <f:facet name="header">
                                  <h:outputText value="Column2" />
                         <h:outputText value="record.value2"
                         </f:facet>        
            </rich:dataTable>

            Whith that code I got: (with ascendent/descendent sorting from richfaces to column1 and column2)

            column1 | column2 |
            value1 | value2 |
            value1 | value2 |
            value1 | value2 |
            value1 | value2 |
            value1 | value2 |
            value1 | value2 |

            BUT I DON'T KNOW HOW ADD TO THIS TABLE THE THIRD COLUMN WICH iS DIVIDED INTO THREE SUBCOLUMNS

            column1 | column2 | column3    |
            value1 | value2 | s1 | s2 | s3 |
            value1 | value2 | s1 | s2 | s3 |
            value1 | value2 | s1 | s2 | s3 |
            value1 | value2 | s1 | s2 | s3 |
            value1 | value2 | s1 | s2 | s3 |
            value1 | value2 | s1 | s2 | s3 |



            • 3. Re: rich:datatable and sorting (data table)
              Tim Evers Master

              Hmm, sorry about that... I better go back and read that doco again :S


              Anyways, why can't you just move your column headers out into the facet section on their own and then use colspan=3 your third column header?


              Like this:


              <rich:dataTable>
                  <f:facet name="header">
                      <rich:column sortBy="#{record.value1}">
                          <h:outputText value="column1"/>
                      </rich:column>
                      <rich:column sortBy="#{record.value2}">
                          <h:outputText value="column2"/>
                      </rich:column>
                      <rich:column colspan="3" sortBy="#{record.s1}">
                          <h:outputText value="column3"/>
                      </rich:column>
                  </f:facet>
                  <rich:column>
                      <h:outputText value="#{record.value1}"/>
                  </rich:column>
                  <rich:column>
                      <h:outputText value="#{record.value2}"/>
                  </rich:column>
                  <rich:column>
                      <h:outputText value="#{record.s1}"/>
                  </rich:column>
                  <rich:column>
                      <h:outputText value="#{record.s2}"/>
                  </rich:column>
                  <rich:column>
                      <h:outputText value="#{record.s3}"/>
                  </rich:column>
              </rich:dataTable>
              


              • 4. Re: rich:datatable and sorting (data table)
                Tim Evers Master

                hmm, I think I missed you doing some of what I said cause your code is all out of format. Can you surround your code with ` so that it gets formatted better and is easier to read.

                • 5. Re: rich:datatable and sorting (data table)
                  Jonh smith Newbie
                  the problem is move the column headers out into the facet section on their own and then use colspan=3 your third column header. When i do that i lost the sorting functions. the sorting icons does not appear.

                  I don't know how to generate the table with this format yet. Where column1 and column2 are ascendet/descendent sorted by richfaces

                  column1 | column2 | column3 |
                  value1 | value2 | s1 | s2 | s3 |
                  value1 | value2 | s1 | s2 | s3 |
                  value1 | value2 | s1 | s2 | s3 |
                  value1 | value2 | s1 | s2 | s3 |
                  value1 | value2 | s1 | s2 | s3 |
                  value1 | value2 | s1 | s2 | s3 |