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 2010/10/25 16:10:46 UTC

[Myfaces Wiki] Update of "Working_with_auto_sortable_tables" by MatthewToso

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 MatthewToso.
The comment on this change is: Fixed sentence structure, spelling and punctuation.
http://wiki.apache.org/myfaces/Working_with_auto_sortable_tables?action=diff&rev1=12&rev2=13

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

- It's a common requirement to display a data set into a table, and in most cases there is also a need to let the user sort that data set by columns. The most simplest and probably very often encountered case is when the entire data set is returned at once for display, and the sorting should be performed by comparing the values displayed in each cell of a given column (i.e. properties of the row object). You'll need to handle the sorting in the backing bean, and use <t:commandSortHeader> for each sortable column of each data table of yours, like the following:
+ It's a common requirement to display a data set using a table and in most cases there is also a need to let the user sort that data set by columns. The simplest and often encountered case is when the entire data set is returned at once for display and the sorting should be performed by comparing the values displayed in each cell of a given column (i.e. properties of the row object). You'll need to handle the sorting in the backing bean and use <t:commandSortHeader> for each sortable column of each data table of yours like the following:
  
  {{{
  <t:dataTable var="car"
@@ -60, +60 @@

  
  === Enable auto sort on all columns ===
  
- The MyFaces extended data table provides a more straightforward solution for this kind of cases. You only need to specify sortable="true" on the data table, and you'll get the same effect without any other custom code. Please note the use of <t:column> component instead of <h:column> which allows to specify the default sorted column, and the sort(String column) method is not needed any more in your backing bean:
+ The MyFaces extended data table provides a more straightforward solution for these kinds of cases. You only need to specify sortable="true" on the data table and you'll get the same effect without any custom code. Please note the use of the <t:column> component instead of <h:column>, which allows you to specify the default sorted column. The sort(String column) method is not needed any more in your backing bean:
  
  {{{
  <t:dataTable var="car"
@@ -87, +87 @@

  
  === Enable auto sort by columns ===
  
- Automatic sorting can be enabled by each column by setting sortable="true" on each <t:column> component, like in the following example:
+ Automatic sorting can be enabled for each column by setting sortable="true" on each <t:column> component as in the following example:
  
  {{{
  <t:dataTable var="car"
@@ -116, +116 @@

  === How does automatic sorting work ===
  
  If sortable="true" the data table will do the following:
-  1. wrapp the current model with a sortable one and make it the current model (this wrapper model is provided by MyFaces, and the model gets wrapped only if it's not already sortable)
+  1. Wraps the current model with a sortable one and makes it the current model (this wrapper model is provided by MyFaces and the model gets wrapped only if it's not already sortable)
-  2. determine which columns are sortable and wrapp the current content of the header facet with a command sort header component
+  2. Determines which columns are sortable and wraps the current content of the header facet with a command sort header component
-  3. while iterating over the sortable columns, get the first output component child of the column and find the property of the row object that is used to display the cell content, from its value attribute
+  3. While iterating over the sortable columns, gets the first output component child of the column and finds the property of the row object that is used to display the cell content from its value attribute
   
- This would get the table into the same state as if you had specified the sort header in each column's header facet yourself. Then the sorting is handled in the sortable model. 
+ This gets the table into the same state as if you had specified the sort header in each column's header facets yourself. Then the sorting is handled in the sortable model. 
  
  === How are the sort properties determined ===
  
- When sorting is enabled on the data table, or on each column separately, the sort property will be determined from the value attribute of the first output component found in the column's children list. This is done by parsing the expression string of the value binding. For example, this a column:
+ When sorting is enabled on the data table or on each column separately, the sort property is determined from the value attribute of the first output component found in the column's children list. This is done by parsing the expression string of the value binding. For example, in this column:
  {{{
  <t:column>
     <f:facet name="header">
@@ -144, +144 @@

  #{car.color}
  }}}
  
- What we are interested at this point is to get the value "color" as the property of the row object from this expression string. The string is parsed and the first thing it searches for, is the appearence of "car." where "car" is the value of the var attribute of the data table.
+ What we are interested in at this point is to get the value "color" as the property of the row object from this expression string. The string is parsed and the first thing it searches for is the appearance of "car." where "car" is the value of the data table's var attribute.
  
- Of course, this is the simplest case, but more complex case are parsed correctly also, like, nested properties and collections. For example, the following will work also:
+ This is the simplest case but more complex cases are parsed correctly also such as nested properties and collections. For example, the following will work:
  
  {{{
  #{car.color.type} => sort property is "color.type" or #{car.color[3]} => sort property is "color[3]"
  }}}
  
- Another thing to note, it that if the value binding expression is composed from several expressions using some kind of operators, only the first appearence of a property of the row object will be taken. For example:
+ Another thing to note is that if the value binding expression is composed from several expressions using some kind of operators, only the first appearance of a property of the row object will be taken. For example:
  
  {{{
  #{car.price + car.taxes} => the property taken is "price" and this will be used when sorting
@@ -160, +160 @@

  
  === Customizing the sort property ===
  
- If you need to customize the sort property that is used to sort the values for a column, you can use the propertyName attribute of the <t:commandSortHeader> component, or the sortPropertyName attribute of the <t:column> component, cause the sort headers are added only if not already present, usefull when the sorting should be performed by a different property than the displayed one:
+ If you need to customize the sort property that is used to sort the values for a column, you can use the propertyName attribute of the <t:commandSortHeader> component, or the sortPropertyName attribute of the <t:column> component because the sort headers are added only if not already present. This is useful when the sorting should be performed by a different property than the displayed one:
  
  {{{
  <t:column defaultSorted="true" sortable="true">
@@ -211, +211 @@

  
  === Note ===
  
-   * Automatic sorting works only using properties available on a row object, and these must be comparable, i.e, implement the Comparable interface, or else they will be compared as strings
+   * Automatic sorting works only using properties available on a row object and these must be comparable, i.e. implement the Comparable interface, or else they will be compared as strings
    * The sortable attribute is available starting with version 1.1.3 of Tomahawk