User:Badon/Extension:Semantic MediaWiki/Manual/Using templates to custom format multiple queries in a single table

Jump to: navigation, search

An example query that returns all pages in a category (the "+" is a wildcard):

{{#ask: [[Category::+]] 
| ? 
| 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 !! Column 2 !! Column 3 !! Column 4 !! Modification date 

Multiple "show" queries just produce the result, with no formatting. You don't need formatting, because you're already customizing formatting yourself. For even less formatting, you could do link=none on the show queries. The "Modification date" property is a handy meta-property to use to make sure everything is working, since it is always available even if other properties are not set. Template:Table row output looks like this:

| {{#show: {{{1}}} | ?}} 
| {{#show: {{{1}}} | ?Property 2}} 
| {{#show: {{{1}}} | ?Property 3}} 
| {{#show: {{{1}}} | ?Property 4}} 
| {{#show: {{{1}}} | ?Modification date}} 

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.