Skip to content

Conversation

gfoidl
Copy link
Contributor

@gfoidl gfoidl commented Jun 27, 2025

The table data items are displayed by simple toString (internally).

This PR adds the optional property formatter, so you can do something like

function formatTimeStamp(value: Date): string {
    return value.toLocaleString();
}

function formatNumber(value: number): string {
    return value.toLocaleString(undefined, { maximumFractionDigits: 2, minimumFractionDigits: 1 });
}

const columns = [
    { key: "timeStampUtc", label: "Timestamp", formatter: formatTimeStamp},
    { key: "mean"        , label: "Mean"     , formatter: formatNumber   },
    { key: "median"      , label: "Median"   , formatter: formatNumber   },
    { key: "sigma"       , label: "Sigma"    , formatter: formatNumber   }
];

in order to specify a formatter, that will convert each item's property according the given formatter-function.

Note

It's optional to specify the formatter

Comment on lines +255 to +260
const column = props.columns![idx];
const value = item[colName];

return typeof column === "object" && column.formatter
? column.formatter(value)
: value;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that there may be better ways, but that would need quite a bit of code-change.
This was tested with a rather big table, and no perf-problems did occur, so I'm fine with this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant