Sortable
Questions answered by this recipe
How can I give options to sort entries generated by a template as a list or a table?
Description
Sortable provides a way to make list (or tables) of entries, generated by a template with the Fox, the FoxCSV or the CSVTemplate recipe, sortable. All list entries must be displayed in the client page for Sortable to work. This recipe does not work for partially displayed lists where numerous calls to the server are necessary to display all the items. For simple table, it is probably better to simply make the table sortable with class="sortable", but for data formated with a template, Sortable is the only solution.
Each entry involded in sorting must be tagged with the (:sortableval ...:) tag normally in the template. This is how the recipe identifies values to be sorted.
A dropdown list of sorting options is instanciated (normally at the top of the list) with (:sortable ...:) tag.
This extension requires ExtensionHub.
Place Sortable-2024-08-10.zipΔ in the pmwiki/extensions
directory on your server. Optionally you can unzip it.
Configuration
To enable the extension, navigate to SiteAdmin.ExtensionHub, locate the "Sortable" row and press "Edit". On the new page, check the checkbox "Enable configuration" and near the bottom press "Save".
The recipe will be loaded only for pages listed in the ExtensionHub configuration for this recipe.
Usage
Sortable provides two new tags:
- (:sortableval varname "varvalue" <show>:)
- identifies values to be sorted. It is normally added to strategic locations in the Fox, FoxCSV or CSVTemplate template.
- varname is the name of the variable to sort.
- "varvalue" is the value of the variable for this entry. It is a good idea to put it between double quotes.
- show indicates if the value must be visible. Values identified with (:sortableval ...:) are invisible by default. "show" avoid repeating the value twice in the template when it is displayed, not used only in a conditional and not formated differently than the original value.
- (:sortable section_id var<->="label"...:)
- instantiates a dropdown with sorting options.
- section_id is the id of the section to be sorted. Sortable section can be any block tag like (:div:) or (:table:).
- var<-> is the variable to be sorted followed of not with "-" for reverse ordering.
- label is the label displayed in the dropdown for the preceding variable.
Here is complete example with a custom FoxCSV template:
(:csv source=#data template=#tmpl:) (:if false:) [[#tmpl]] (:template first:)Header\\ (:sortable sortable_section field1="F1 in ascending order" field1-="F1 in descending order" field2="F2 in ascending order" field2-="F2 in descending order":) (:div id=sortable_section:)\\ '''F1-F2''' (:template each:)(:div2:)'''(:sortableval field1 "{$$field1}" show:) - '''(:sortableval field2 "{$$field2}" show:) (:div2end:) (:template last:) (:divend:) [[#tmplend]] [[#data]] field1;field2 a;y b;x c;z [[#dataend]] |
See Sortable in action!
Change log / Release notes
- 2024-11-29: First version.
See also
- Cookbook /
- CSVTemplate Allow representing the same CSV data in different locations using templates. (stable)
- Fox Form processor to add, replace, copy, delete content plus upload files and send email notifications using templates and Input markup (stable)
- FoxCSV Display csv tables automatically or via templates; filtering, sorting, editing csv data. (beta)
Contributors
Comments
See discussion at Sortable-Talk
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.