Perspective Table Data and Columns Config from Datasets
When using the JSON return format in a Named Query, the column order and original column datatypes are lost. You can move a Named Query binding to a custom property of the component or view, then use this simple iteration expression to deliver the jsonified content to the table:
Binding on props.data
forEach(
{path.to.source.dataset.prop},
asMap(it())
)
Binding on props.columns (optional)
forEach(
columnsOf({path.to.source.dataset.prop}),
if(
it()[0] = 'special_column_name',
asMap(
'field', it()[0],
'sortable', true,
'editable', true,
'filter', asMap('enabled', true, 'visible', 'on-hover'),
'resizable', true //,
// 'header', asMap('title', replace(runScript(concat("'",it()[0],"'",'.title()')),'_',' ')), // don't do this
// 'render', it()[1] // not necessary (ds column types are implicit)
// add additional properties as needed
),
asMap('field', it()[0])
)
)
@pturmel - can we get a title()
function?
Features employed
- Iterables General behavior of all iterators.
forEach()
Loops through the dataset, calling the nested expression with one row at a time.it()
Delivers the one row in dataset format (same column names and types as the source).asMap()
Converts the first row of the dataset it is given into a mapping (dictionary) of key-value pairs.columnsOf()
: gets column names (and types)