This form contains a table that allows the user to sort the displayed data by clicking the header of the desired column. Sorting is performed by manipulation of the actual data using XForms! No need for an IFX.
The simple sorting algorithm used in this sample performs poorly with large data sets. If you implement a more efficient sorting algorithm, please share it!
The nice part of the approach used is that the sorting algorithm has been pulled out of the header buttons found at the top of the columns and placed into a centralized location in order to promote re-use and maintainability.
Technically, there are actually two variations of the sort algorithm; one for numeric sorts and one for alphabetic. The numeric sort can be found in a field called "START_NUMERIC_SORT" and the alphabetic in "START_ALPHABETIC_SORT". In a production form, these two fields would be made invisible to the user. In order to kick off a sort, a header button simply sets a variable in the XForms model to tell the sort code which column to sort by and then another variable to specify whether this column is numeric or alphabetic. The code in the appropriate START_X_SORT field then takes over and performs the work of sorting the data.
In order to re-use this code in your own form, you will need to perform the following steps:
1. Copy the "logicData" data instance into your form.
2. Copy the START_NUMERIC_SORT and START_ALPHABETIC_SORT fields into your form.
3. Update these fields by replacing "instance('formData')/students/student" with the nodeset of your table.
4. Update these fields by replacing "instance('formData')/students" with the context of your table (xpath reference to parent node of repeating element).
5. Convert the header labels of your table to buttons (use source code view).
6. Modify each of your header buttons so they wrap the following xforms:trigger. Configure the "sortByElement" setvalue action for the current column and make sure the second setvalue action sets the appropriate node (startNumericSort or startAlphabeticSort) to match the data type of the column you're sorting.