Question
It is often necessary to display some tabular data in the context panel of a cell. For example, a list of products in an order, in the cycles table without entering the cycle itself.
Answer
What is shown in the picture is a special functionality of the Data type field. If you format the rowList in a certain way, it will be displayed in the context panel like this.
How the template looks:
{
"data": [
{
"name_1": "content_here_1_1",
"name_2": "content_here_1_2",
"name_3": true
},
{
"name_1": "content_here_2_1",
"name_2": "content_here_2_2",
"name_3": false
}
],
"settings": {
"columns": [
"name_1",
"name_2",
"name_3"
],
"headRow": {
"name_1": "Title for name_1",
"name_2": "Title for name_2",
"name_3": "Title for name_3"
},
"headColumn": true
}
}
The data contains the data for display — rowList. There may be more columns in the data than will be shown. The ones that will be shown are those specified in the settings key — in the columns key.
In settings, the display settings are formatted:
columns
— the names of the columns from data that need to be shown.
headRow
— the header row where we pass the row from the name column and its corresponding title.
headColumn
— true | false, whether to bold the values in the first column.
To make the value in the field look good, it is also assigned formatting with overlapping text:
f1=: setFormat(text: "Some value"; textasvalue: true)
The template can be assembled directly in the field with code, or stored somewhere and pulled with a select.
I usually have two fields in the table — a technical (hidden) one with data without settings data_from_teh_field
and one shown to the user:
=: rowCreate(field: "data" = #data_from_teh_field; field: "settings" = $settings)
settings: rowCreate(field: "columns" = $columns; field: "headRow" = $headRow; field: "headColumn" = true)
columns: json`["name_1","name_2","name_3"]`
headRow: rowCreate(field: "name_1" = "Title 1"; field: "name_2" = "Title 2"; field: "name_3" = "Title 3")
Usually, for such a field, the width of the context panel is increased through the field settings via the Context Panel Width parameter.