Difference between revisions of "Category talk:Tabular data/doc"
blackwiki>Mxn (Another example) |
blackwiki>Mxn |
||
| Line 11: | Line 11: | ||
A row index of <code>1</code> refers to the first row in the table. A row index of <code>-1</code> refers to the last row in the table. It is an error to specify a row index of <code>0</code>. | A row index of <code>1</code> refers to the first row in the table. A row index of <code>-1</code> refers to the last row in the table. It is an error to specify a row index of <code>0</code>. | ||
| − | + | === Examples === | |
| + | |||
| + | Latest death toll in [[c:Data:COVID-19 Cases in Santa Clara County, California.tab]] (regardless of when the table was last updated): | ||
| + | |||
| + | {{#invoke:Demo|module|demo_module={{BASEPAGENAME}}|demo_module_func=cell|COVID-19 Cases in Santa Clara County, California.tab|output_row=-1|output_column=deaths}} | ||
== <code>lookup</code> == | == <code>lookup</code> == | ||
| Line 20: | Line 24: | ||
Usage: {{mlx|{{BASEPAGENAME}}|''lookup''|''Page name.tab''|search_value{{=}}''Value to find in column''|search_column{{=}}''Name of column to search in''|output_column{{=}}''Name of column to output''}} | Usage: {{mlx|{{BASEPAGENAME}}|''lookup''|''Page name.tab''|search_value{{=}}''Value to find in column''|search_column{{=}}''Name of column to search in''|output_column{{=}}''Name of column to output''}} | ||
| − | Examples: | + | === Examples === |
| + | |||
| + | Total confirmed case count in [[c:Data:COVID-19 Cases in Santa Clara County, California.tab]] on the day that the county issued a [[stay-at-home order]]: | ||
| − | + | {{#invoke:Demo|module|demo_module={{BASEPAGENAME}}|demo_module_func=lookup|COVID-19 Cases in Santa Clara County, California.tab|search_value=2020-03-16|search_column=date|output_column=totalConfirmedCases}} | |
| − | + | ||
| + | Total number of administrators on all Wikimedia wikis: | ||
| + | |||
| + | {{#invoke:Demo|module|demo_module={{BASEPAGENAME}}|demo_module_func=lookup|Wikipedia statistics/data.tab|search_value=total.all|search_column=site|output_column=admins}} | ||
== <code>wikitable</code> == | == <code>wikitable</code> == | ||
| Line 32: | Line 41: | ||
Usage: {{mlx|{{BASEPAGENAME}}|''wikitable''|''Page name.tab''}} | Usage: {{mlx|{{BASEPAGENAME}}|''wikitable''|''Page name.tab''}} | ||
| − | {{Collapse top| | + | === Examples === |
| + | |||
| + | {{Collapse top|COVID-19 statistics in Santa Clara County, California}} | ||
{{#invoke:Demo|module|demo_module={{BASEPAGENAME}}|demo_module_func=wikitable|COVID-19 Cases in Santa Clara County, California.tab}} | {{#invoke:Demo|module|demo_module={{BASEPAGENAME}}|demo_module_func=wikitable|COVID-19 Cases in Santa Clara County, California.tab}} | ||
{{Collapse bottom}} | {{Collapse bottom}} | ||
| + | |||
| + | === Implementation notes === | ||
The implementation of this function incorporates {{tl|n/a}} (to represent null values), {{tl|yes}} (true), and {{tl|no}} (false). The templates themselves cannot be reused because they are incompatible with the [[mw:Extension:Scribunto/Lua reference manual#HTML library|<code>mw.html</code>]] library, which builds the table using an HTML DOM instead of pure wikitext. | The implementation of this function incorporates {{tl|n/a}} (to represent null values), {{tl|yes}} (true), and {{tl|no}} (false). The templates themselves cannot be reused because they are incompatible with the [[mw:Extension:Scribunto/Lua reference manual#HTML library|<code>mw.html</code>]] library, which builds the table using an HTML DOM instead of pure wikitext. | ||
Revision as of 20:21, 10 May 2020
Error: {{Module rating}} must be placed in the Module namespace.
This module provides basic functions for interacting with tabular data on Wikimedia Commons.
Contents
cell
Returns the value of the cell at the given row index and column name.
Usage: {{#invoke:Tabular data|cell|Page name.tab|output_row=Index of row to output|output_column=Name of column to output}}
A row index of 1 refers to the first row in the table. A row index of -1 refers to the last row in the table. It is an error to specify a row index of 0.
Examples
Latest death toll in c:Data:COVID-19 Cases in Santa Clara County, California.tab (regardless of when the table was last updated):
Lua error in Module:Tabular_data at line 35: attempt to index local 'data' (a boolean value).
lookup
Returns the value of the cell in the given output column of the row matching the search key and column.
This function is reminiscent of LOOKUP() macros in popular spreadsheet applications, except that the search key must match exactly. (On the other hand, this means the table does not need to be sorted.)
Usage: {{#invoke:Tabular data|lookup|Page name.tab|search_value=Value to find in column|search_column=Name of column to search in|output_column=Name of column to output}}
Examples
Total confirmed case count in c:Data:COVID-19 Cases in Santa Clara County, California.tab on the day that the county issued a stay-at-home order:
Lua error in Module:Tabular_data at line 97: attempt to index local 'data' (a boolean value).
Total number of administrators on all Wikimedia wikis:
{{#invoke:Tabular data|lookup
|search_column=site
|output_column=admins
|search_value=total.all
|Wikipedia statistics/data.tab}}
5506
wikitable
Returns the entire data table as a (rather plain) table.
Usage: {{#invoke:Tabular data|wikitable|Page name.tab}}
Examples
COVID-19 statistics in Santa Clara County, California
|
|---|
|
Lua error in Module:Tabular_data at line 153: attempt to index local 'data' (a boolean value). |
Implementation notes
The implementation of this function incorporates {{n/a}} (to represent null values), {{yes}} (true), and {{no}} (false). The templates themselves cannot be reused because they are incompatible with the mw.html library, which builds the table using an HTML DOM instead of pure wikitext.
Internationalization
You can most likely port this template to a wiki in another language without making major modifications. The wikitable function automatically localizes the table's description, column titles, and license name into the wiki's content language. It also formats numbers according to the content language. However, you should localize the cells representing true, false, and null by changing the values in the messages, bgColors, and colors variables to match the wiki's own {{yes}}, {{no}}, and {{n/a}} templates, respectively.
See also
- {{Json2table}} and {{#invoke:Json2table|json2table}}