Skip to main content

Column and Cell Rendering

When creating a table widget, you can customize the columns and cells to create many different data visualization options. Below are the key components and settings you can use to define column and cell rendering:

Column Definitions

Each widgets.json entry for your table widget can have a columnsDefs property that defines the columns for the table. Note that setting columnsDefs is entirely optional - tables will work with default settings, and columnsDefs should only be used when you need to fine-tune the visualization.

When defined, columnsDefs is an array of column definitions, each with the following properties:

PropertyTypeDescriptionOptions/Default
fieldstringThe name of the field from the JSON data. Must match a key in the data source.-
headerNamestringThe display name of the column header shown in the widget.Defaults to field name
cellDataTypestringDefines the data type of the cell."text", "number", "boolean", "date", "dateString", "object". Defaults to "text"
formatterFnstringSpecifies a function to format the data."int", "none", "percent", "normalized", "normalizedPercent", "dateToYear". Defaults to "none"
renderFnstringSpecifies a rendering function for cell data."greenRed", "titleCase", "cellOnClick"
renderFnParamsobjectParameters for the render function.Example: {"actionType": "groupBy"}
widthnumberThe width of the column in pixels.-
maxWidthnumberThe maximum width of the column in pixels.-
minWidthnumberThe minimum width of the column in pixels.-
hidebooleanWhether to hide the column from the table.Defaults to false
pinnedstringPins the column to the left or right of the table."left" or "right"

Example Configuration

Below is an example of how you might configure your columns in the widgets.json file:

"columnsDefs": [
{
"field": "column1",
"headerName": "Column 1",
"cellDataType": "text",
"formatterFn": "none",
"renderFn": "titleCase",
"width": 100,
"maxWidth": 200,
"minWidth": 50,
"hide": false,
"pinned": "left"
},
{
"field": "column2",
"headerName": "Column 2",
"cellDataType": "number",
"formatterFn": "int",
"renderFn": "greenRed",
"width": 150
}
]

Customizing Cell Rendering

Cell rendering can be customized using the renderFn property, which allows you to apply specific styles or transformations to the data. For example, using "greenRed" can visually indicate positive or negative values, while "titleCase" can format text data to title case. You can also use the cellOnClick render function to group data by the cell value - see the [Grouping and Parameters](/terminal/custom-backend/Advanced Controls/Grouping and Parameters) section for more details on this.

Cell Data Type

The cellDataType property defines the data type of the cell, which affects how the data is displayed and interacted with in the widget. Here are the options available:

PropertyTypeDescription
textstringDisplays the data as plain text. Suitable for string data that does not require special formatting
numberstringDisplays the data as a number. Can be formatted further using the formatter function property
booleanstringDisplays the data as a boolean value
datestringDisplays the data as a date object. Can be formatted to show different date representations
dateStringstringDisplays the data as a string representation of a date
objectstringDisplays the data as an object. Useful for complex data structures requiring custom rendering logic

Formatter Function

The formatterFn property specifies a function used to format the data in the table. This allows for customization of how numerical and date data is presented. Here are the allowed values:

ValueTypeDescription
intstringFormats the number as an integer, removing any decimal places
nonestringDoes not apply any formatting to the number, displaying it as is
percentstringAdds a percentage sign to the number, which is useful for data that represents percentages
normalizedstringMultiplies the number by 100, which can be useful for normalizing data to a percentage scale
normalizedPercentstringMultiplies the number by 100 and adds a percentage sign, converting a decimal to a percentage (e.g., 0.5 becomes 50%)
dateToYearstringConverts a date to just the year, which is useful for summarizing date data to a yearly level