Editing cells in a Dynamic Table
How cells in a Dynamic Table can be edited depends on whether they contain expressions or placeholders. Not sure what the difference is between expressions and placeholders? The difference is explained in another topic: Expressions or placeholders?
Note that even in a dynamic table where most of the cells contain expressions, cells can have a direct link to a data field. A cell that shows a subtotal always has a direct link to a data field.
Cells with expressions
Table cells with expressions can be edited in the following ways.
-
Additional text can be typed in a cell directly, before or after the expression. For example: Price: {{currency ItemPrice}}.
-
You can add expressions to include data that is located somewhere else in the Data Model. Note that the expression will have to indicate where that data is relative to the table row (associated with a detail record) that contains the expression. E.g. use ../ to navigate one level up. For example: {{../year}}. (See Accessing data at different levels.) When you drag and drop or double-click a field to add it to the table, the correct expression is added automatically.
-
There is a number of Format Helpers that you can use in an expression to format the output differently. For example: {{dateLong DueDate}}.
-
Other types of Helpers can also be used to modify cells in a Dynamic Table. See Logic Helpers and Block Helpers.
-
To change the content or style of a cell or span based on the value of a data field, you could write a custom Helper (see Creating custom Helpers) or a script (Writing your own scripts).
How to target the first or last row
To target the first or last row, you can use the @first
and @last
data variables in a Block Helper. A few examples.
Example: {{#if @first}}Policy conditions{{/if}}
In the above example, the {{if}} Block Helper only outputs the text 'Policy conditions' if the cell is in the first row.
Example: <span class="{{#if or @first @last}}emphasize{{/if}}">{{ItemDesc}}</span>
Here, a Block Helper adds a class to a Span element only if it is in the first or last row. The class can then be used as selector for a CSS style or a script.
Getting the index of a row
In a Block Helper, the @index
data variable can be used to work with the index number of the row. Note that the index is zero-based.
Example: {{add @index 1}}: {{ItemDesc}}
The above expression outputs the number of the row, followed by the value of the ItemDesc field. E.g. "4: Upgrade Starter to Web".
Since @index is zero-based, the add
Helper is used to add 1 to it.
Tip: add
is one of the Logic Helpers that is available out of the box; see Logic Helpers.
Cells with placeholders
Dynamic Table cells with a placeholder by default have a direct link to a data field.
To find out whether a cell or span has a direct link to a data field, select it and:
-
Take a look on the Attributes pane. If under Other, the Field drop-down or Sum field point to a data field in the detail table, the element has a direct link to a data field .
-
Switch to the Source view. Elements with a direct link to a data field have a
data-field
ordata-sum
attribute.
Cells with a direct link to a data field are edited as follows.
-
Which data field is linked to a cell and how the value is formatted can be changed via the Attributes pane.
-
Any text in the cell - including the placeholder - will be replaced with the value of the data field the cell is linked to, when the template is merged with data. To learn how to mix data and text in these cells, see Mixing text and data in a cell with a direct link to a data field.
Changing content based on a value
Changing the contents of a cell or row in a Dynamic Table, based on the value of a data field, requires a script. See Using scripts in Dynamic Tables.
Mixing text and data in a cell with a direct link to a data field
By default, each Dynamic Table cell that has a direct link to a data field shows a placeholder. For example: @CompanyName@ refers to a data field named CompanyName. However, these placeholders are not used as selector.
Instead, if a cell has the data-field
or data-sum
attribute, the software will replace the entire contents of that cell with a value: the current value of the data field, or a running total, respectively.
(For information about data- attributes see: A Dynamic Table's data- attributes).
Any text that was added in Design mode will disappear.
In order to mix data and text in a cell with a data- attribute, you should remove the data-field
or data-sum
attribute, respectively, from the cell itself and then put that attribute on an element inside the cell.
Here's how to do that.
-
In the Workspace, open the Design tab.
-
Select the cell (see Selecting an element).
-
On the Attributes pane, set Field or Sum to None.
-
Type text in the cell, before and/or after the placeholder.
-
Select the placeholder, right-click it and select Wrap in Span...
-
Select the new Span element.
-
On the Attributes pane, set Field or Sum to the desired data field.
-
Reapply the format if needed (see Formatting values).
Formatting values
Values in Dynamic Table cells can be formatted in different ways. A date value, for example, could be displayed as "Apr 2, 2016" (short date) or "4/2/16 12:00 AM" (medium date/time).
Which formats are possible depends on the data type of the field that contains the value (see Data types).
Selecting a format
The format of each value can be chosen when creating a table. For an explanation of the possible formats see Formatting variable data.
How you change the formatting of values in an existing table depends on whether the cell or span contains an expression (e.g. {{fieldname}}) or is directly linked to a data field (see Expressions or placeholders?).
If the cell or span contains an expression:
-
There is a number of Format Helpers that you can type in an expression to format the output differently.
If the cell or span has a direct link to a data field:
-
Select the element that contains the value and then use the Format drop-down on the Attributes pane.
- Open the Source tab and manually add the desired format to the cell using the
data-format
attribute (see A Dynamic Table's data- attributes).