Deciding which textual element to use
In many cases, you can use several textual elements to accomplish the same task. For example, you can use a label element, a text element, or a data element to display a static report title like the one in the following example:
Sales Report for Quarter One, 2014
When you apply complex formats or combine static text with dynamic data, you need to use the appropriate textual element to achieve the best results. This section provides guidelines and examples for determining the best textual element to use for different purposes. The rest of this chapter provides details about using each element, except the data element, which is described in the previous chapter.
Formatting words differently in a static string
The previous example showed how you can use a label, text, or data element to display a static title. To format words in the title differently, as shown in the following example, you must use the text element. In the example, some words appear as plain text and some in bold. With the label and data elements, formats apply to the entire string.
Sales Report for Quarter One, 2014
Combining static text with dynamic data
To display the following text, where Order Total: is static text, and the number is a dynamic, or calculated, value, use a text element or a data element:
Order Total: 74050
To format the dynamic value so that it appears as a currency value with comma separators and decimal places, as shown in the following example, use the text element. The text element enables you to format different parts of text differently.
Order Total: $74,050.00
Alternatively, use a label element and a data element to display the preceding text. Use the label element to display the static text portion, Order Total:, and the data element to display the dynamic portion, as shown in Figure 7‑3. When the data element consists of just the number value, you can use the Format Number property to format the number.
Figure 7‑3 Label and data elements in the layout editor
Figure 7‑4 shows the output of the preceding report design.
Figure 7‑4 Label and data elements in a report
The difference between using the label and data elements and using the text element is how you control the space between the static text and the dynamic value. Using the text element, you can easily specify one character space between the two. If you use the label and data elements, the spacing is determined by various factors, such as text alignment and column widths. In the previous example, the label element and data element are both right‑aligned.
Displaying dynamic data that contains HTML tags
Many data sources store large amounts of text that contain internal formatting, as shown in the following example. Data like this is typically stored in CLOB fields.
<html><b>Customer log 04/12/05 13:45:00</b><br>Customer called
to enquire about order. He says order 2673-9890 was supposed
to arrive on 04/10/05. Records show that the order is on
backorder. Customer says he received no notification about the
status of his order. He wants to cancel the order if it is not
shipped by 04/15/05.<br><i>Action Items:</i><ul><li>Call
distributor about delivery status. <li>Send email to customer
about delivery status.</ul></html>
To display the text with the specified HTML formats, use the text element or the dynamic text element. To combine static text with dynamic text, use the text element. If you add static text to the dynamic text element, for example, "Customer Issue: " + row["Issue"], the dynamic data appears in the report exactly as it appears in the field, including the HTML tags.
Figure 7‑5 shows how the text element displays the static text, Customer Issue:, with the dynamic text. The text element converts the HTML tags to formatting and layout attributes. For example, text within the <b> and </b> tags appears in bold.
Figure 7‑5 Static and dynamic text in a text element
Figure 7‑6 shows how the dynamic text element displays the text when you add static text to the dynamic text. The HTML tags appear because the content is converted to string type.
Figure 7‑6 Static and dynamic text in a dynamic text element
Displaying dynamic data that a JavaScript expression returns
An expression is any valid combination of literals, variables, functions, or operators that evaluates to a single value. Both the text element and the data element can display the results of any valid JavaScript expression, including multiline expressions, such as the one in the following example:
if (row["creditScore"] > 700){
displayString = "Your loan application has been approved."
}
else{
displayString = "Your loan application has been denied."
}