How do I set the caption for one or more columns? I think as it stands the each field name is rendered in PascalCase. Does it require the use of a column template?
To apply a column template, it must be tagged with $:/tags/Table/BodyTemplate and also critically the field name to which the column template applies should be specified in the tbl-column-list field. Unfortunately tbl-column-list isn’t mentioned in any documentation I can find - could this be addressed please? I stumbled across this field in a post on this forum otherwise I would have been none the wiser
Hi Nick,
Yes, the column caption is the name of field and converted to Titlecase like myfield→ Myfield
I did not notice the custom template creation has been deleted in recent docs. I think there was instruction for this. I will look and fix it!
There are some examples in this forum for creating custom template, but in general
templates/body → control column content
templates/header→ control column header
templates/footer→ control column footer
In any template the field tbl-column-list is a key field to control which field is shown through this template.
Thanks Mohammad, I understand that everything is conflgurable via templates, but I was wondering whether something as commonly required as setting the caption for a field in a table might be made a little easier?
Am I correct in saying that currently, to set a custom caption for a field, you have to create both custom /bodyand/header templates and tbl-column-list to a new pseudo-field name which is specified in the fields list in the table-dynamic macro?
I think some sort of override might be possible - I will have a ponder
OK @Mohammad I’ve got custom captions to work thuswise:
Create an application/json tiddler with mappings from field names to desired caption:
{
"fieldName1": { "Caption": "My nice newish caption" },
"fieldName2": { "Caption": "My horrible caption" }
}
Clone $:/plugins/kookma/shiraz/templates/header/default to e.g. $:/njb/plugins/kookma/shiraz/templates/header/default, set tag $:/tags/Table/HeaderTemplate and move list order to top.
Wrap the contents of . $:/njb/plugins/kookma/shiraz/templates/header/default in the following:
It all works fine, and is relatively simple but seems like a lot of work and column sorting doesn’t work.
Any thoughts on a better way of doing this? I thought it would be nice to specify the name and desired caption in the tbl-column-list e.g. by passing fields like this:
Insert the contents of $:/plugins/kookma/shiraz/templates/header/default somewhere ‘local’, wrapped in a macro (here headerCaptionMacro) definition with a parameter (desiredCaption here) for the desired caption somewhere conventient, tagging with $:/tags/Macro:
Create a tiddler containing the macro call like so <<headerCaptionMacro "Clinic date">> with the $:/tags/Table/HeaderTemplate tag and the tbl-column-list field set to the name of the field you wish to be handled.
so that they look for a caption field in the tiddler for the current column, and uses that caption if it exists, defaulting to the title if the caption field does not exist?
You can make a tiddler titled the way the field name is titled (assuming your dynamic-table columns are fields). Then, create a caption field within that tiddler.
Of course, second-guessing my quick reply above, caption might not be the best choice for a field to determine the dynamic table header, since other functions already harness the caption field. Perhaps tbl_caption or something like that would be better. (I often prefer very short headers for columns if the data is short, so that horizontal space is not wasted. But some fields, like bibtex-year, are baked into other plugins, and take more horizontal space than the contents within the column below.)
Spelling out the solution merely gestured-at above:
Suppose I have a dynamic-table column for the bibtex-year field, and I always want the dynamic-table column’s header to be just year (which I do!) … or 📘year or whatever.
On my solution: I make a tiddler called bibtex-year and give it a tbl_caption field with contents: year.
I can do this, on the fly, for any column header, without messing around each time with templates. Column headers still default to their usual field names.
If you like this behavior, you just have to edit Shiraz’s shadow tiddler for default column headers as follows:
“caption tiddlers” in any convenient location tagged with $:/njb/tags/ColumnCaption, title is field name, tbl_caption is desired caption
$:/plugins/kookma/shiraz/templates/header/default overridden (I had thought that I could do this by cloning to a $:/njb/… tiddler and tagging with $:/plugins/kookma/shiraz/templates/header/default, moving this tiddler’s tag position to the top of the list, but this didn’t work ). Content:
<span style="text-transform: capitalize;"><$text text=<<currentColumn>>/></span> replaced by <<caption>>
Code added to top of $:/plugins/kookma/shiraz/templates/header/default:
This should make edits when $:/plugins/kookma/shiraz/templates/header/default is updated as simple as possible, and the “caption tiddlers” can be put in locations which make sense to the application.