DataTableFormatters

Ready-made formatters for DataTableHeader.format — money, plain numbers, percentages, dates, and booleans.

DataTableHeader<Order>(
key = "total",
title = "Total",
value = { it.total }, // raw, so the column sorts numerically
format = DataTableFormatters.currency(), // formatted, so the cell reads "$1,299.00"
align = TextAlign.End,
)

Every formatter here is total: it renders null as its nullText and falls back to toString() for a value of a type it cannot handle, rather than throwing. A formatter runs during layout, once per visible cell, and an exception there would take the table down with it.

Each returned formatter holds its locale and pattern, so build it once — in a remember, or alongside the headers it belongs to — rather than per recomposition.

Functions

Link copied to clipboard
fun boolean(trueText: String = "Yes", falseText: String = "No", nullText: String = ""): (Any?) -> String

Renders a Boolean as words instead of true / false.

Link copied to clipboard
fun currency(currency: Currency? = null, decimals: Int? = null, locale: Locale = Locale.getDefault(), nullText: String = ""): (Any?) -> String

Formats a Number as money, with the currency symbol and separators of a locale.

Link copied to clipboard
fun date(pattern: String, locale: Locale = Locale.getDefault(), zone: ZoneId = ZoneId.systemDefault(), nullText: String = ""): (Any?) -> String

Formats a date or time with a DateTimeFormatter pattern.

Link copied to clipboard
fun number(decimals: Int = 0, grouping: Boolean = true, locale: Locale = Locale.getDefault(), nullText: String = ""): (Any?) -> String

Formats a Number with a fixed number of decimal places.

Link copied to clipboard
fun percent(decimals: Int = 0, fraction: Boolean = true, locale: Locale = Locale.getDefault(), nullText: String = ""): (Any?) -> String

Formats a Number as a percentage.