Help:Table format
| Table format |
|---|
| What: |
| Outputs the result in a table. |
| Provided by: |
| Semantic MediaWiki |
| Added in version: |
| 0.4 |
| Removed in version: |
| still supported |
| Further Requirements: |
| none |
| Format name: |
| table |
| Authors: |
| Markus Krötzsch |
| Categories: |
| misc |
The result format table is used to format query results as tables. The format table is the default way of formatting query results for all queries that have one or more additional printout statements. It is very similar to the broadtable format.
Contents |
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | Whole number | 20 | The maximum number of results to return |
| offset | Whole number | 0 | The offset of the first result |
| headers | Text | show | Display the headers/property names |
| mainlabel | Text | no | The label to give to the main page name |
| link | Text | all | Show values as links |
| intro | Text | empty | The text to display before the query results, if there are any |
| outro | Text | empty | The text to display after the query results, if there are any |
| default | Text | empty | The text to display if there are no query results |
There are no inline query parameters specific to the table format. The parameter headers=hide is specifically useful for hiding the header of tables (in most other cases, it is enough to use empty printout labels to hide the titles of printout statements).
Example
{{#ask: [[Category:City]] [[located in::Germany]]
| ?population
| ?area#km² = Size in km²
}}
This produces the following output:
| Population | Size in km² | |
|---|---|---|
| Berlin | 3,391,409 | 891.85 km²344.343 sqmi |
| Frankfurt | 679,664 | 248.31 km²95.872 sqmi |
| Munich | 1,259,678 | 310.43 km²119.857 sqmi |
| Stuttgart | 595,452 | 208.754 km²80.6 sqmi |
Applying CSS formatting
As of version 1.6.2 SMW uses the native MediaWiki sortable tables. Thus this format now provides several ways for custom formatting to be applied to tables:
- One or more overall CSS classes can be set for the table, using the "class=" parameter.
- Each column in the table gets a class name that derives from the column name. For instance, if a column is titled "Capital city", the column's class will be "Capital-city".
- Rows in the table each get either the class "row-odd" or "row-even", depending on whether the row is odd or even.
In this way, specific formatting, like colors and font sizes, can be set across a single table, or for a specific column, or can be set for alternating rows. (The recommended way to set any custom CSS in the wiki is by modifying the page "MediaWiki:Common.css".)
- Example for alternating row colours
The example below will result in the display of alternating rows.
/* even and odd in tables*/ .smwtable .row-even {background-color:#FFF;} .smwtable .row-odd {background-color:#CDE6EA;}
Sorting
Tables have a special feature for sorting their contents by any of the columns in the table. See Help:Selecting pages for general comments on sorting and a comparison to the wiki's query result sorting. Browsers without JavaScript enabled will not see the buttons for sorting at all.