Virtual columns
Sometimes you may need a column that uses combinations of columns in the data. Rather than create a new column in the data file, you can build a "virtual" column from any existing ones. For instance, say that you'd like to include a functioning link in a table or tooltip. If your data source contains a column titled Title
and a column titled URL
you could build a new column named Link
using e.g.:
columns:
- name: 'Link'
template: '<a href="{{ URL }}">{{ Title }}</a>'
Virtual columns must have name
and template
properties. The template
can make use of string templates, filter functions, and any existing columns in the data.
For example, let's create a new Tooltip contents
column:
columns:
- name: 'Tooltip contents'
template: '{{ name }}: {{ value | toLocaleString() }}'
This new column is built from existing name
and value
columns but we pass the value
into the filter toLocaleString()
to format it. The new column can be referenced elsewhere using Tooltip contents
in the same way as you would any pre-existing column in the data. You could have achieved the same result by creating this content directly in the data file but using virtual columns may help to keep that file cleaner.
Defining virtual columns
is also a very simple way to rename an exisiting column heading if you need to.