#

API Docs for: 3.10.3
Show: Inherited Protected Private Deprecated

# DataTable.BodyView.Formatters Class

Defined in: `datatable/js/formatters.js:19`
Module: datatable-formatters
Parent Module: datatable

Available since 3.8.0

Registry of function producing cell formatting functions. Allows for names to be used in the column definition `formatter` property:

    {key:"myColumn", formatter:"date"}

These functions are not meant to be used directly. Instead, they will be automatically called when their names are used as values for the `formatter` property in a columnd definition. They will be called just once per rendering cycle and will receive the column configuration. They are expected to return a function that will then be called once per row and will do the actual formatting. They are expected to do all the preparatory once-per-render work so that the actual formatting function doesn't need to repeat it.

- Index
- Methods

## Item Index

### Methods

- _date static
- boolean static
- button static
- currency static
- date static
- email static
- link static
- localDate static
- localDateTime static
- localTime static
- number static

## Methods

### `_date`

(

- `format`

)
Function private static

Defined in `datatable/js/formatters.js:138`

Returns a date formatting function based on the given format.

#### Parameters:

- `format` String

  The format spec definition.

#### Returns:

Function: A formatter function that formats numerical data as currency.

### `boolean`

(

- `col`

)
Function static

Defined in `datatable/js/formatters.js:63`

Returns a formatter function that returns the texts `"true"` or `"false"` and assigns the CSS classNames `yui3-datatable-true` or `yui3-datatable-false` based on the value of the cell.

If either a `booleanLabels` configuration object is defined for the column or a `booleanLabels` configuration attribute is defined for the datatable, the formatter will use the values for the properties `true` or `false` of either of those objects as the text to show.

It returns `null`s or `undefined`s unchanged so that the `emptyCellValue` configuration attribute will eventually apply.

     {key:"active", formatter: "boolean", booleanLabels: {
         "true": "yes",
         "false": "no"
     }}

#### Parameters:

- `col` Object

  The column definition.

#### Returns:

Function: A formatter function that formats boolean data.

### `button`

(

- `col`

)
Function static

Defined in `datatable/js/formatters.js:40`

Returns a formatter that produces a BUTTON element using the value of the `buttonLabel` column definition attribute as its label or the text `Click` if not found.

Applies the CSS className `yui3-datatable-button` to the cell.

#### Parameters:

- `col` Object

  The column definition.

#### Returns:

Function: A formatter function that produces a `<button>` element.

### `currency`

(

- `col`

)
Function static

Defined in `datatable/js/formatters.js:100`

Returns a formatter function that formats values as currency using the `Y.Number.format` method. It looks for the format to apply in the `currencyFormat` property of the column or in the `currencyFormat` attribute of the whole table.

    {key: "amount", formatter: "currency", currencyFormat: {
        decimalPlaces:2,
        decimalSeparator: ",",
        thousandsSeparator: ".",
        suffix: "&euro;"
    }}

See Y.Number.format for the available format specs.

Anything that cannot be parsed as a number will be returned unchanged.

Applies the CSS className `yui3-datatable-currency` to the cell.

#### Parameters:

- `col` Object

  The column definition.

#### Returns:

Function: A formatter function that formats numerical data as currency.

### `date`

(

- `col`

)
Function static

Defined in `datatable/js/formatters.js:155`

Returns a date formatting function. It looks for the format to apply in the `dateFormat` property of the column or in the `dateFormat` attribute of the whole table.

    {key: "DOB", formatter: "date", dateFormat: "%I:%M:%S %p"}

See Y.Date.format for the available format specs.

Anything that is not a date is returned unchanged.

Applies the CSS className `yui3-datatable-date` to the cell.

#### Parameters:

- `col` Object

  The column definition.

#### Returns:

Function: A formatter function that formats dates.

### `email`

(

- `col`

)
Function static

Defined in `datatable/js/formatters.js:222`

Returns a function that produces email links. If the column definition contains a property `linkFrom` it will use the value in that field for the link, otherwise, the same column value will be used for both link and text.

    {key: "contact", formatter: "email", linkFrom: "contactEmail"}

It will use the respective `emptyCellValue` column configuration attribute for each of the value and the link if either is empty. If the link value is still empty, it will return the value with no link.

Applies the CSS className `yui3-datatable-email` to the cell.

#### Parameters:

- `col` Object

  The column definition.

#### Returns:

Function: A formatter function that adds a mailto: link to the value.

### `link`

(

- `col`

)
Function static

Defined in `datatable/js/formatters.js:259`

Returns a function that produces links. If the column definition contains a property `linkFrom` it will use the value in that field for the link, otherwise, the same column value will be used for both link and text.

    {key: "company", formatter: "link", linkFrom: "webSite"}

It will use the respective `emptyCellValue` column configuration attribute for each of the value and the link if either is empty. If the link value is still empty, it will return the value with no link.

Applies the CSS className `yui3-datatable-link` to the cell.

#### Parameters:

- `col` Object

  The column definition.

#### Returns:

Function: A formatter function that adds a link to the value.

### `localDate`

() Function static

Defined in `datatable/js/formatters.js:175`

Returns a date-only (no time part) formatting function using the current locale.

    {key: "DOB", formatter: "localDate"}

Anything that is not a date is returned unchanged.

Applies the CSS className `yui3-datatable-date` to the cell.

#### Returns:

Function: A formatter function that formats dates.

### `localDateTime`

() Function static

Defined in `datatable/js/formatters.js:205`

Returns a date formatting function using the current locale.

    {key: "DOB", formatter: "localDateTime"}

Anything that is not a date is returned unchanged.

Applies the CSS className `yui3-datatable-date` to the cell.

#### Returns:

Function: A formatter function that formats dates.

### `localTime`

() Function static

Defined in `datatable/js/formatters.js:190`

Returns a time-only (no date part) formatting function using the current locale.

    {key: "startTime", formatter: "localTime"}

Anything that is not a date is returned unchanged.

Applies the CSS className `yui3-datatable-date` to the cell.

#### Returns:

Function: A formatter function that formats dates.

### `number`

(

- `col`

)
Function static

Defined in `datatable/js/formatters.js:296`

Returns a formatter function that formats values using the `Y.Number.format` method. It looks for the format to apply in the `numberFormat` property of the column or in the `numberFormat` attribute of the whole table.

     {key: "weight", formatter: "number", numberFormat: {
         decimalPlaces:2,
         decimalSeparator: ",",
         thousandsSeparator: ",",
         suffix: "kg"
     }}

See Y.Number.format for the available format specs.

Anything that cannot be parsed as a number will be returned unchanged.

Applies the CSS className `yui3-datatable-number` to the cell.

#### Parameters:

- `col` Object

  The column definition.

#### Returns:

Function: A formatter function that formats numerical data as currency.