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.
BooleanFormatter
Renders a boolean value as 'Yes' or 'No'.
DateFormatter
Formats a datetime object into a more readable date.
DialogModalFormatter
Renders a link that opens a dialog modal with detailed information.
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.
URLFormatter
Generates a clickable link for a URL.
Only http/https values are turned into a link. Anything else
(e.g. a javascript: URI, or a value with no scheme at all) is
rendered as plain, escaped text instead — cell values can come from
untrusted data, and letting an arbitrary scheme or unescaped markup
through here would let one row inject a link or script for everyone
who views the table.
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.
Each distinct user id is looked up at most once per table render — the lookup is memoised on the table instance — rather than re-querying a user id that recurs across many rows on the same page (e.g. a "created by" column where a handful of users own most of the rows).