Adding sorting to a data table
With the Data Table component, you can display data from
a database or other data source in a table format.
Before you begin
About this task
You can use the sorting function in the data table component to make individual columns in a data table sortable. First you will use the sort function to add a sort icon to the column header and make the column header clickable. Then you will write the code that performs the data sorting in the Quick Edit view. You will also create a new command button in order to reset multiple columns at the same time.
Procedure
To add sorting to a data table:
Results
Sort order options
Each sortable column can have a default value of one of
the values shown in Table 1. The default value is the initial sort
order of the column when the page with the data table opens. The third
column, Attribute Value, shows the value to set in the JSP for each
sort order.
About this task
| Sort Order | Description | Attribute Value |
|---|---|---|
| Ascending Off | Sort can be toggled between Sort Ascending and Not Sorted. Sorting not turned on when the page loads. | sortasc |
| Ascending On | Sort can be toggled between Sort Ascending and Not Sorted. Sorting is turned on when the page loads. | sortascon |
| Descending Off S | Sort can be toggled between Sort Descending and Not Sorted. Sorting is not turned on when the page loads. | sortdesc |
| Descending On | Sort can be toggled between Sort Descending and Not Sorted. Sorting is turned on when the page loads. | sortdescon |
| Bidirectional | Sort can be toggled among Sort Ascending, Sort Descending, and Not Sorted. Sorting is not turned on when the page loads. | sortbi |
| Bidirectional Up | Sort can be toggled among Sort Ascending, Sort Descending, and Not Sorted. Sort Descending is turned on when the page loads. | sortbiup |
| Bidirectional Down | Sort can be toggled among Sort Ascending, Sort Descending, and Not Sorted. Sort descending is turned on when the page loads. | sortbidown |
Only one column can be sorted at a time. When you sort one column, all of the other columns automatically revert to the default sort orders.
Configuring the sort attributes
You can set all of the <hx:sortHeader> attributes
in the Properties view.
About this task
| Attribute | Description |
|---|---|
| id | In the sorting action that you write, you can use this attribute to identify which sortHeader the user has selected. |
| defaultSortOrder | Default sort order for this column. |
| srcAscending, srcAscendingOn, srcDescending, srcDescendingOn, srcBi, srcBiUp, srcBiDown | The sort arrow image comes from the <hx:sortHeader> style class by default. You can use these attributes to override the images specified in the stylesheet. |
| styleClass | The style class that the sort header uses. |
Resetting multiple columns
You can create a new command button in order to reset
multiple columns at the same time.
Procedure
To create a new command button and reset multiple columns: