You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2011/01/20 12:38:15 UTC

[Myfaces Wiki] Update of "Working_with_auto_sortable_tables" by ThorstenGunkel

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The "Working_with_auto_sortable_tables" page has been changed by ThorstenGunkel.
The comment on this change is: Added an example for sorting while using t:columns after I did not find a working example for it.
http://wiki.apache.org/myfaces/Working_with_auto_sortable_tables?action=diff&rev1=13&rev2=14

--------------------------------------------------

               preserveSort="true">
          <h:column>
              <f:facet name="header">
-                 <t:commandSortHeader columnName="type" arrow="true">     
+                 <t:commandSortHeader columnName="type" arrow="true">
-                     <h:outputText value="Type"/>                    
+                     <h:outputText value="Type"/>
                  </t:commandSortHeader>
              </f:facet>
-             <h:outputText value="#{car.type}" />            
+             <h:outputText value="#{car.type}" />
          </h:column>
          <h:column>
              <f:facet name="header">
-                 <t:commandSortHeader columnName="color" arrow="true">                    
+                 <t:commandSortHeader columnName="color" arrow="true">
                      <h:outputText value="Color" />
                  </t:commandSortHeader>
              </f:facet>
-             <h:outputText value="#{car.color}" />                    
+             <h:outputText value="#{car.color}" />
          </h:column>
  </t:dataTable>
  }}}
@@ -192, +192 @@

  </t:column>
  }}}
  
+ === Enable auto sort with dynamic columns ===
+ 
+ Instead of listing all columns with a t:column element, you can also have them inserted dynamically with a t:columns element:
+ 
+ {{{
+ <t:dataTable var="car"
+              value="#{list.cars}"
+              sortColumn="#{list.sortColumn}"
+              sortAscending="#{list.ascending}"
+              preserveDataModel="true"
+              preserveSort="true">
+       <t:columns value="#{list.columns}"
+                  var="column"
+                  sortable="true">
+         <f:facet name="header" >
+ 	      <t:commandSortHeader columnName="#{column.field}"
+ 	                           propertyName="#{column.field}"
+ 	                           arrow="true" >
+     	      <h:outputText value="#{column.header}" />                    
+           </t:commandSortHeader>
+         </f:facet>
+         <h:outputText value="#{column.value}" />
+       </t:columns>
+ </t:dataTable>
+ }}}
+ 
+ Please note that column.field needs to return the name of the column attribute and not the human readable title of the column. Otherwise sorting won't work.
+ 
  === Static sorting ===
  
  If all you want to do is sort your row data in the display and you don't want to enable any user-specified sorting, you can specify the following: