I have a table ‘sources’ with a M2M relationship to table ‘labels’ through table ‘source_label’. In a table block (based on table ‘labels’) added the field source, which shows all the sources related to a certain label.
I stead of showing all the sources, I like to see only the number of sources (COUNT). Is this possible?
yes, just hover to jsfield and select the labels column, and write Javascript
ctx.element.innerHTML = ctx.value.length;
I’ve found this: I’ve added as a JSField with this code:
function JsReadonlyField() {
const React = ctx.React;
const { prefix, suffix, overflowMode } = ctx.model?.props || {};
const whiteSpace = overflowMode === 'wrap' ? 'pre-line' : 'nowrap';
const count = Array.isArray(ctx.value) ? ctx.value.length : 0;
return (
<span style={{ whiteSpace }}>
{prefix}
{count}
{suffix}
</span>
);
}
ctx.render(<JsReadonlyField />);
Is this ok or can it be more efficient?
That also works but mine is only one line so whatever I guess