Datatable formatters
we-datatable renders cells automatically with a formatter component, chosen from the column definition returned by the server: field.formatter.value, or field.type when no formatter is set. A column with an explicit item.<key> slot is never auto-formatted.
Built-in formatters
| Key | Component | Output |
|---|---|---|
date | WeDtLuxonFormatter | dd/MM/yyyy |
datetime | WeDtLuxonFormatter | dd/MM/yyyy HH:mm (when field.type is datetime) |
boolean | WeDtBooleanFormatter | $booleanOn icon in success / $booleanOff icon in offColor |
dataset | WeDtDatasetFormatter | Dataset labels, as chips or plain text |
Every formatter receives the same props:
| Prop | Type | Description |
|---|---|---|
value | any | Cell value (item[column.key]) |
item | object | Whole row |
field | object | Column field definition, plus the column filter |
WeDtBooleanFormatter
Extra prop offColor (string, default 'grey-lighten-1'): icon color for falsy values.
WeDtLuxonFormatter
Formats the value with $lux (see lux); empty values render nothing.
WeDtDatasetFormatter
Maps each value (or each element of an array value) to an entry of field.filter.type.dataset ({ value, text, color?, props? }) and renders its text (or the raw value when not found).
field.formatter.component:'v-chip'renders av-chipper value, anything else adivfield.formatter.component_props: props for every chip; each dataset entry can add its ownprops, and itscoloris applied
Example column definition (from the API):
{
"id": "status",
"field": {
"type": "string",
"formatter": { "value": "dataset", "component": "v-chip", "component_props": { "size": "small", "variant": "flat" } }
},
"filter": {
"type": {
"dataset": [
{ "value": "active", "text": "Active", "color": "success" },
{ "value": "closed", "text": "Closed", "color": "error" }
]
}
}
}Custom formatters
Register extra formatters (or override the built-in ones) in app.config.ts under we.datatables.formatters. The key is matched against field.formatter.value / field.type:
// app.config.ts
import IconFormatter from '~/components/IconFormatter.vue'
export default defineAppConfig({
we: {
datatables: {
formatters: {
icon: markRaw(IconFormatter),
},
},
},
})<!-- components/IconFormatter.vue -->
<template>
<v-icon v-if="value">
{{ value }}
</v-icon>
</template>
<script setup lang="ts">
defineProps<{
value?: string
item?: Record<string, any>
field?: Record<string, any>
}>()
</script>