Custom Formatting
Custom formatting in SquaredUp lets you control how you display and format your data using Mustache-style expressions with JavaScript operations. This feature was previously called format expressions.
For example, you may wish to:
- Perform calculations on values
{{ $['myColumn'] / 1000 }}
- Combine text and/or multiple columns
Progress: {{ $['myColumn'] }} out of {{ $['myColumnTwo'] }}
- Manipulate a string to remove/replace part of it
{{ $['myColumn'].substring(0, 20) }}
Custom formatting changes are purely cosmetic, meaning that while you can format a value of 1
to display as 1000000
, any sorting or aggregation you perform on that column will still use the original value of 1
.
Configuring custom formatting
- From the tile editor, select the Columns tab.
- Click on the type you wish to configure, e.g. String, Number etc.
- Set the formatting mode to Custom
- Enter your custom expression to change the formatting.
- As you type, the preview will be updated.
How to use custom formatting
Custom formatting uses Mustache-style placeholders ({{ }}
) that contain JavaScript. Within a placeholder, you can use JavaScript to access the current row of data as well as other variables like the array of all rows, or current index. A single expression may contain multiple placeholders as well as literal text. For example:
Progress: {{ $['myColumn'] }} out of {{ $['myColumnTwo'] }}
This would display something like this: Progress: 10 out of 20
.
Accessing column data
To access the value from a particular column, use the $
object. Accessing each column as a property on that object, e.g. $.myColumn
or $['myColumn']
will return the value for a column called myColumn
. From there you can use standard JavaScript to manipulate the value.
Other placeholder variables
IntelliSense
The editor used for inputting an expression also supports IntelliSense to make suggestions and show commands/properties that are available. IntelliSense is automatically triggered as you type, or can be manually triggered using Ctrl+Space
.
Error handling and troubleshooting
If a placeholder throws an error or contains invalid JavaScript syntax, the error message is captured and used as the output of the placeholder for debugging purposes.