Help:Broadtable format

From semantic-mediawiki.org
(Redirected from Help:Broadtable format)
Help:Broadtable formatBroadtable format/zh-hans
Broadtable format
Outputs the results in a broad table.
Further Information
Provided by: Semantic MediaWiki
Added: 0.4
Removed: still supported
Requirements: none
Format name: broadtable
Enabled? Indicates whether the result format is enabled by default upon installation of the respective extension. yes
Authors: Markus Krötzsch
Categories: misc
Table of Contents

The result format broadtable is used to format query results as tables. It is identical to result format "table"Outputs the results in a table (default for queries with printout statements). except that it stretches the table to 100% of the available width.

Parameters[edit]

General[edit]

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

NoteNote:  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[edit]

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
sep text empty The separator between results
Semantic MediaWiki 3.0.0Released on 11 October 2018 and compatible with MW 1.27.0 - 1.31.x. introduced a set of predefined classes supporting a datatable output1 which allows to search the table and to display more results without bloating the display of the table on the wiki page.23
  • Possible options for parameter "class" are: datatable, datatable compact, datatable cell-border or the combination datatable compact cell-border.4. These classes makes use of the "DataTables" table plug-in for jQuery5.
  • Using these classes produces a basic output as offered by result format "Datatables"Provides a complete porting of DataTables JavaScript library into Semantic MediaWiki provided by extension "Semantic Result Formats"Provides additional formats for semantic queries which also makes use of the "DataTables" table plug-in for jQuery. The latter is however more powerful in its usage.2

Semantic MediaWiki 3.1.0Released on 23 September 2019 and compatible with MW 1.31.0 - 1.33.x. brought the smwtable-clean class allowing for another alternative to the wikitable smwtable class combination.6

Sorting[edit]

Tables have a special feature for sorting their contents by any of the columns in the table. See 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[edit]

Default display
{{#ask:
 [[Category:City]]
 [[Located in::Germany]] 
 |mainlabel=City
 |?Population
 |?Area#km²=Size in km²
 |format=broadtable
}}

This produces the following output:

CityPopulationThe number of inhabitants of some geographical place.Size in km²
Berlin3,520,061891.85 km²344.34 sqmi <br />
Cologne1,080,394405.02 km²156.38 sqmi <br />
Frankfurt679,664248.31 km²95.87 sqmi <br />
Munich1,353,186310.43 km²119.86 sqmi <br />
Stuttgart606,588207.35 km²80.06 sqmi <br />
Würzburg126,63587.63 km²33.83 sqmi <br />
Display using classes "smwtable-clean" and "sortable"
{{#ask:
 [[Category:City]]
 [[Located in::Germany]] 
 |mainlabel=City
 |?Population
 |?Area#km²=Size in km²
 |format=broadtable
 |class=smwtable-clean sortable
}}

This produces the following output:

CityPopulationThe number of inhabitants of some geographical place.Size in km²
Berlin3,520,061891.85 km²344.34 sqmi <br />
Cologne1,080,394405.02 km²156.38 sqmi <br />
Frankfurt679,664248.31 km²95.87 sqmi <br />
Munich1,353,186310.43 km²119.86 sqmi <br />
Stuttgart606,588207.35 km²80.06 sqmi <br />
Würzburg126,63587.63 km²33.83 sqmi <br />
More examples

Applying CSS formatting[edit]

As of Semantic MediaWiki 1.6.2Released on 20 September 2011 and compatible with MW 1.15.x - 1.18.x. the native MediaWiki sortable tables are used. 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;
}

Data value type attributes[edit]

Semantic MediaWiki 1.9.0Released on 3 January 2014 and compatible with MW 1.19.0 - 1.22.x. introduced type related attribution allowing to apply specific formatting rules based on the datatype uses (data value types like "_dat", "_num" etc.) used in a column.7

The class attribute is a concatenated string that includes "smwtype" + "datavalue typeId" resulting in "smwtype_dat" for the data value of datatype "Date". 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;
}

Examples[edit]


References

  1. ^  Semantic MediaWiki: GitHub pull request gh:smw:2420
  2. a b  Semantic MediaWiki: GitHub issue comment gh:smw:2420:294453317
  3. ^  Semantic MediaWiki: Sandbox example sb:smw:2420:1
  4. ^  Semantic MediaWiki: Sandbox example sb:smw:2420:2
  5. ^  " - A tables plug-in for jQuery.
  6. ^  Semantic MediaWiki: GitHub pull request gh:smw:4048
  7. ^  
    Gerrit commit gerrit:smw:53520