Help:Table format
Table format | |
---|---|
Outputs the result in a table. | |
Available languages | |
de, en, zh-hans | |
Further Information | |
Provided by: | Semantic MediaWiki |
Added: | 0.4 |
Removed: | still supported |
Requirements: | none |
Format name: | table |
Enabled by default: Indicates whether the result format is enabled by default upon installation of the respective extension. |
yes |
Authors: | Markus Krötzsch |
Categories: | misc |
Group: | |
Table of Contents | |
↓ INFO ↓
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.
Parameters
General
Parameter | Type | Default | Description |
---|---|---|---|
source | text | empty | Alternative query source |
limit | whole number | 50 | The maximum number of results to return |
offset | whole number | 0 | The offset of the first result |
link | text | all | Show values as links |
sort | list of texts | empty | Property to sort the query by |
order | list of texts | empty | Order of the query sort |
headers | text | show | Display the headers/property names |
mainlabel | text | no | The label to give to the main page name |
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 |
searchlabel | text | ... further results | Text for continuing the search |
default | text | empty | The text to display if there are no query results |
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).
Format specific
Parameter | Type | Default | Description |
---|---|---|---|
class | text | sortable wikitable smwtable | An additional CSS class to set for the table |
transpose | yes/no | no | Display table headers vertically and results horizontally |
Example
{{#ask: [[Category:City]] [[located in::Germany]] | ?population | ?area#km² = Size in km² }}
This produces the following output:
Population | Size in km² | |
---|---|---|
Berlin | 3,520,061 | 891.85 km² 344.343 sqmi |
Cologne | ||
Frankfurt | 679,664 | 248.31 km² 95.872 sqmi |
Munich | 1,353,186 | 310.43 km² 119.857 sqmi |
Stuttgart | 606,588 | 207.36 km² 80.062 sqmi |
Würzburg |
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;}
DataValue type attributes
SMW 1.9 introduces type related attribution allowing to apply specific formatting rules based on the dataValue type (_dat, _num etc.) used in a column.
The class attribute is a concatenated string that includes "smwtype" + "datavalue typeId" resulting in "smwtype_dat" for the date/time dataValue. If you want all numeric representations (prerequisite is that the property selected for display is of datatype Number) in a table to be formatted on the right side, you would need to add:
/* DataValue type formatting */ .smwtable .smwtype_num {text-align: right;}
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.
Examples