Data Tokens
Data tokens are primarily used to provide a looping or repetitive mechanism for data tables and to represent the data fields within those tables.
[EACHROW]
The each row token is used to enclose a repeating sequence for each row of a table. Everything between the [EACHROW] and [/EACHROW] tokens will be rendered for each row of the table.
Syntax Variations
Table Parameter
The table parameter allows you to access multiple query sources. If your query returns multiple resultsets back, each one is assigned an id starting at
table1 and continuing in sequence
table2,
table3 etc., one for each resultset.
- [EACHROW]
- repeats for each row of the first table in the dataset (set of tables)
- [EACHROW table="table1"]
- repeats for each row of the table named table1
- [EACHROW table="table3"]
- repeats for each row of the table named table3 (ie. third resultset)
Filter Parameter
The filter parameter allows you to select a subset of your rows
- [EACHROW table="table1" filter="Column1=10"]
- repeats for each row of the table named table1 where Column1 equals 10
- [EACHROW table="table1" filter="Column1>10"]
- repeats for each row of the table named table1 where Column1 is greater than 10
Rows Parameter
The rows parameter allows you to select a subset of rows based on the row number. The property takes a valid regular expression and matches that against the row number to determine if the row is rendered or not.
- [EACHROW rows="^1$"]
- shows the data for the first row of a returned query
- [EACHROW rows="^[1|5|8]$"]
- repeats for rows 1, 5 and 8
- [EACHROW rows="^\d*[13579]$"]
- repeats for all odd rows of the returned query
- [EACHROW rows="^\d*[02468]$"]
- repeats for all even rows of the returned query
Sort Parameter
The sort parameter allows you to change the sort order of your query, of course you could also do this within your query as well.
- [EACHROW table="table1" sort="Column1 DESC"]
- repeats for each row of the table named table1 ordered by Column1 in descending order
- [EACHROW table="table1" sort="Column1,Column5"]
- repeats for each row of the table named table1 ordered by Column1 and then Column5
Nesting
- [EACHROW] tokens may be nested within each other to provide a loop within a loop
Column Data¶
Accessing field level data within the [EACHROW] is as simple as specifying the column name or column number withing square brackets.
Syntax Variations
- [Column1]
- outputs the data value from the column name Column1
- [5]
- outputs the data value from the 5th column
Special Tokens
Row Based
- [#RowNumber]
- outputs the current row number
- [#OddEven]
- outputs either odd or even depending on the row count
Examples
For the purpose of these examples lets assume we have this table providing input into our template.
Table1 - a list of departments
DepartmentId Name
1001 HR
1002 Sales
1003 Logistics
1004 Manufacturing
1005 Accounting
Example 1 - Default
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
[EACHROW]
<tr>
<td>[DepartmentId]</td><td>[Name]</td></tr>
[/EACHROW]
</table>
results in
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
<tr>
<td>1001</td><td>HR</td></tr>
<tr>
<td>1002</td><td>Sales</td></tr>
<tr>
<td>1003</td><td>Logistics</td></tr>
<tr>
<td>1004</td><td>Manufacturing</td></tr>
<tr>
<td>1005</td><td>Accounting</td></tr>
</table>
Note: If we replace [EACHROW] with [EACHROW table="Table1"] we get the exact same output as above.
Example 2 - Sorting
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
[EACHROW table="Table1" sort="Name"]
<tr>
<td>[DepartmentId]</td><td>[Name]</td></tr>
[/EACHROW]
</table>
results in this sorted output
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
<tr>
<td>1005</td><td>Accounting</td></tr>
<tr>
<td>1001</td><td>HR</td></tr>
<tr>
<td>1003</td><td>Logistics</td></tr>
<tr>
<td>1004</td><td>Manufacturing</td></tr>
<tr>
<td>1002</td><td>Sales</td></tr>
</table>
Example 3 - Filtering
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
[EACHROW table="Table1" filter="DepartmentId>1003"]
<tr>
<td>[DepartmentId]</td><td>[Name]</td></tr>
[/EACHROW]
</table>
results in this filtered output
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
<tr>
<td>1004</td><td>Manufacturing</td></tr>
<tr>
<td>1005</td><td>Accounting</td></tr>
</table>
Example 4 - Using ordinal column tokens¶
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
[EACHROW]
<tr>
<td>[1]</td><td>[2]</td></tr>
[/EACHROW]
</table>
In this example, the output is the exact same as Example 1, but we've changed the column tokens to positional tokens [1] and [2] instead of [DepartmentId] and [Name].
results in
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
<tr>
<td>1001</td><td>HR</td></tr>
<tr>
<td>1002</td><td>Sales</td></tr>
<tr>
<td>1003</td><td>Logistics</td></tr>
<tr>
<td>1004</td><td>Manufacturing</td></tr>
<tr>
<td>1005</td><td>Accounting</td></tr>
</table>
Example 5 - #RowNumber and #OddEven¶
<table>
<tr>
<th>Row</th>
<th>Id</th>
<th>Name</th>
</tr>
[EACHROW]
<tr class="[#OddEven]">
<td>[#RowNumber]</td><td>[DepartmentId]</td><td>[Name]</td></tr>
[/EACHROW]
</table>
results in
<table>
<tr>
<th>Row</th><th>Id</th><th>Name</th></tr>
<tr class="odd">
<td>1</td><td>1001</td><td>HR</td></tr>
<tr class="even">
<td>2</td><td>1002</td><td>Sales</td></tr>
<tr class="odd">
<td>3</td><td>1003</td><td>Logistics</td></tr>
<tr class="even">
<td>4</td><td>1004</td><td>Manufacturing</td></tr>
<tr class="odd">
<td>5</td><td>1005</td><td>Accounting</td></tr>
</table>