Help:DataTable2
Help:DataTable2
The <datatable2> tag creates a data table to store structured data for use in RiskModel calculations or DropDown menus. It is typically defined on a "/Data" subpage to organize risk-related data for RiskiPedia pages.
Syntax
The <datatable2> tag uses these attributes:
- `table`: (Required) A unique name for the table (e.g., `time_of_day`).
- `columns`: (Required) A pipe-separated list of column names (e.g., `time_period|time_fatality_multiplier`).
The tag’s content includes a `<head>` section with wikitext table headers (starting with `!`) and data rows using pipe (`|`) separators.
Basic syntax:
<datatable2 table="TableName" columns="column1|column2"> <head> !Column 1 !Column 2 </head> Value1|Value2 Value3|Value4 </datatable2>
Usage
1. Use the <datatable2> tag to define a table, typically on a "/Data" subpage, specifying a unique `table` name and `columns`. 2. In the `<head>` section, define column headers using wikitext table syntax (e.g., `!Header`). 3. Add data rows with values separated by pipes (`|`), matching the order of columns. 4. Reference the table in a <dropdown> tag to display its data in a menu, or use its column names as variables in a RiskModel or RiskDisplay calculation.
The <datatable2> tag stores data that can be selected via <dropdown> or used in risk calculations with <riskmodel> or <riskdisplay>.
Examples
Time of Day Risk Factors
Define a table for time-of-day risk multipliers:
<datatable2 table="time_of_day" columns="time_period|time_fatality_multiplier|time_injury_multiplier"> <head> !Time of day !Fatality risk multiplier !Injury risk multiplier </head> Day|1.0|1.0 Night|3.56|1.47 </datatable2>
This table, named "time_of_day", can be used in a <dropdown> to select "Day" or "Night", or its columns (`time_fatality_multiplier`, `time_injury_multiplier`) can be variables in a <riskmodel>.
Seatbelt Use Risk Factors
Define a table for seatbelt usage:
<datatable2 table="seatbelt_use" columns="belt_status|belt_fatality_multiplier|belt_injury_multiplier"> <head> !Seat-belt usage !Fatality risk multiplier !Injury risk multiplier </head> Worn|1.0|1.0 Not worn|1.82|2.0 </datatable2>
This table, "seatbelt_use", supports a <dropdown> for selecting "Worn" or "Not worn" and provides variables like `belt_fatality_multiplier` for calculations.
Combined with RiskModel and Dropdown
Use a table with a <dropdown> and <riskmodel> on a driving risk page:
<datatable2 table="DrivingConditions" columns="condition|fatality_risk"> <head> !Driving condition !Fatality risk multiplier </head> Dry|1.0 Wet|1.5 </datatable2> <riskmodel name="DrivingRisk" calculation="base_probability * fatality_risk">Your risk is about {result}%</riskmodel> <dropdown table="DrivingConditions" title="Select condition" label_column="condition" /> <riskdisplay model="DrivingRisk" />
This defines a "DrivingConditions" table, a <riskmodel> using its `fatality_risk` column, a <dropdown> to select a condition, and a <riskdisplay> to show the result.
Notes
- The `table` name must be unique, especially on "/Data" subpages, to avoid conflicts.
- Column names in the `columns` attribute must match the order of headers and data in the table.
- Use column names as variables in RiskModel or RiskDisplay calculations, or specify a column in a <dropdown> `label_column`.
- Tables are often defined on "/Data" subpages but can be referenced from main pages using full names (e.g., `PageName/Data:TableName`).
Troubleshooting
- **Error: "dropdown: cannot find DataTable2 table X"** – Ensure the `table` name matches exactly and exists on the current page or a "/Data" subpage.
- **Calculation fails** – Verify that variable names in <riskmodel> or <riskdisplay> calculations match column names in the <datatable2> `columns` attribute.
- **Dropdown shows no data** – Check that the table has data rows and the `label_column` in <dropdown> matches a column name.
- **Table not rendering** – Ensure the `<head>` section and data rows use correct wikitext table syntax (`!` for headers, `|` for data).
For related features, see RiskModel documentation, RiskDisplay documentation, DropDown documentation, or RiskParameter documentation.