User:Badon/Extension:Semantic MediaWiki/Manual/Using templates to custom format a table query
An example query that returns all pages in a category (the "+" is a wildcard):
{{#ask: [[Category::+]] | ? | ?Property 2 | ?Property 3 | ?Property 4 | ?Modification date | format=template | template=Table row output | introtemplate=Table start | outrotemplate=Table end | link=none }}
Using the "sortable" class on a templatized table output allows users to sort any field, in any direction, just by clicking on it. The "wikitable" class just gives you standard table styling. Template:Table start looks like this:
{| class="wikitable sortable" ! Page name !! Property 2 !! Property 3 !! Property 4 !! Modification date |-
Using unnamed parameters, Template:Table row output looks like this:
| {{{1}}} | {{{2}}} | {{{3}}} | {{{4}}} | {{{5}}} |-
All that is needed is to end the wiki table. Template:Table end looks like this:
|}
All three of those templates together will assemble a table, where the sorting can be changed by the user due to the usage of the "sortable" class. Of course, the default Semantic MediaWiki table already does that for simple queries, but if you have something more complicated, this is how you get a sortable table for yourself. You can customize this to display however you like it.