Skip to main content

format

Description​

Optional. Defines how to format values for FilterEditor

Usage​

format?: string | ((value: any) => string);

Parameters​

format can be one of the following:

  • a formatting function for "number", "tuple" or "date" filter types: (value: number|Date) => string
  • a formatting string for date types

Example​

The example below shows how to add a function to convert month numbers to labels:

<script>
import { FilterEditor } from "@svar-ui/svelte-filter";
import { en } from "@svar-ui/core-locales";

const options = [0, 1, 2];

// Converts numbers to full month names
const numberToMonth = v => en.calendar.monthFull[v];

</script>

<FilterEditor type="tuple"{options} format={numberToMonth} />

Related articles: FilterEditor Guide