Skip to content

Available Built-in Formatters

The tables extension comes with several built-in formatters that you can use to format the data in your table columns.

Using formatter is simple; you just need to import the desired formatter from ckanext.tables.shared.formatters and add it to the formatters list in the ColumnDefinition.

from ckanext.tables.shared import formatters, ColumnDefinition

ColumnDefinition(
    field="timestamp",
    formatters=[(formatters.DateFormatter, {"date_format": "%Y-%m-%d %H:%M"})],
)

Below is a list of the available built-in formatters along with a brief description of each.


ActionsFormatter

Renders a template snippet to display row-level actions.

Options
  • template (str): The path to the template to render. Defaults to tables/formatters/actions.html.

BooleanFormatter

Renders a boolean value as 'Yes' or 'No'.

DateFormatter

Formats a datetime object into a more readable date.

Options
  • date_format (str): The strftime format for the output. Defaults to "%d/%m/%Y - %H:%M".

DialogModalFormatter

Renders a link that opens a dialog modal with detailed information.

Options
  • template (str): The path to the template to render inside the modal. Defaults to tables/formatters/dialog_modal.html.
  • modal_title (str): The title of the modal dialog. Defaults to "Details".
  • max_length (int): The maximum length of the preview text before truncation. Defaults to 100.

JsonDisplayFormatter

Renders a JSON object using a template snippet for display.

Must be combined with tabulator_formatter="html" in the ColumnDefinition to ensure proper HTML rendering in the frontend.

ListFormatter

Renders a list as a comma-separated string.

NoneAsEmptyFormatter

Renders a None value as an empty string.

TextBoldFormatter

Renders text in bold.

TrimStringFormatter

Trims a string to a specified maximum length.

Options
  • max_length (int): The maximum length of the string. Defaults to 79.
  • add_ellipsis (bool): Whether to add "..." if the string is trimmed. Defaults to True.

URLFormatter

Generates a clickable link for a URL.

Options
  • target (str): The target attribute for the link. Defaults to "_blank".

UserLinkFormatter

Generates a link to a user's profile with a placeholder avatar.

This is a custom, performant implementation that avoids expensive user_show calls for every row by using a placeholder. The value for this formatter should be a user ID.

Options
  • maxlength (int): Maximum length of the user's display name. Defaults to 20.
  • avatar (int): The size of the avatar placeholder in pixels. Defaults to 20.