Skip to content

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 ​

KeyComponentOutput
dateWeDtLuxonFormatterdd/MM/yyyy
datetimeWeDtLuxonFormatterdd/MM/yyyy HH:mm (when field.type is datetime)
booleanWeDtBooleanFormatter$booleanOn icon in success / $booleanOff icon in offColor
datasetWeDtDatasetFormatterDataset labels, as chips or plain text

Every formatter receives the same props:

PropTypeDescription
valueanyCell value (item[column.key])
itemobjectWhole row
fieldobjectColumn 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 a v-chip per value, anything else a div
  • field.formatter.component_props: props for every chip; each dataset entry can add its own props, and its color is applied

Example column definition (from the API):

json
{
  "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:

ts
// app.config.ts
import IconFormatter from '~/components/IconFormatter.vue'

export default defineAppConfig({
  we: {
    datatables: {
      formatters: {
        icon: markRaw(IconFormatter),
      },
    },
  },
})
vue
<!-- 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>

Source Code ​