Studio supports a variety of data types. Instead of being defined directly on fields, data types are defined on Formats. A Format controls formatting along with other behaviour.
const fields = [
{
id: 'athlete',
format: 'textFormat' // textFormat uses the `string` data type
},
// ... other fields
];
When using Synchronous Data Sources and not providing fields, the format will be Inferred from the Data.
Data Types Copy Link
Each of the data types are described in the table below. The input type is the JavaScript type that is supported in the source data. The default Format is the Format that will be used when inferring fields.
| Data Type | Input Type | Default Format |
|---|---|---|
string | string | textFormat |
number | number | integerFormat / decimalFormat |
boolean | boolean | booleanFormat |
date | Date | string | number | dateFormat |
datetime | Date | string | number | dateTimeFormat |
For data and datetime, the string value is expected to be in ISO-8601 format, and the number value is Unix epoch.
Formats Copy Link
Provided Formats Copy Link
| Format | Data Type | Default Display Format |
|---|---|---|
textFormat | string | Text Value |
integerFormat | number | 100000 |
decimalFormat | number | 123.00 |
booleanFormat | boolean | True / False (or Locale equivalent) |
dateFormat | date | 31/12/2025 (or equivalent for user's locale) |
dateTimeFormat | datetime | 31/12/2025, 13:00:00 (or equivalent for user's locale/timezone) |
percentageFormat | number | 50% |
currencyFormat | number | 123.00 |
Each display format can be changed via the Format Options. It is possible to Override the Provided Formats globally or for individual fields.
Inferring Formats Copy Link
It is generally best practice to provide Field definitions with desired formats.
When using Synchronous Data Sources and not providing fields, the format is inferred from the data. Inference is based on the first non-null value in the data.
number values will be inferred as integerFormat if the first value is an integer, otherwise as decimalFormat.
Date values will be inferred as dateTimeFormat.
When dates are represented as strings, they will be inferred as dateFormat if there is no time component, otherwise as dateTimeFormat.
Format Options Copy Link
All the formats with number data type use Intl.NumberFormat to perform the default formatting. This is set in the field/format options as format. This allows control over the number of decimal places plus many other things. E.g. currencyFormat will not show a currency by default, but the currency can be set in the Intl.NumberFormat object.
Similarly, dateFormat and dateTimeFormat use Intl.DateTimeFormat in options.format.
See below for examples demonstrating how to customise this.
Overriding Provided Formats Copy Link
Provided Formats can be overridden by passing the result of the createFormats function to the formats property of the data sources definition.
The overrides allow you to change any of the Format Properties (except the data type).
<ag-studio
:data="data"
/* other studio properties ... */>
</ag-studio>
this.data = {
formats: createFormats({
overrides: {
textFormat: {
valueFormatter: ({ value }) => value.toUpperCase(),
},
currencyFormat: {
options: {
format: new Intl.NumberFormat(undefined, {
style: 'currency',
currency: 'GBP',
currencyDisplay: 'narrowSymbol',
maximumFractionDigits: 2,
}),
},
},
},
}),
// sources, etc.
};It is also possible to override all of the value formatting/serializing properties for individual fields by setting them on the field definition.
<ag-studio
:data="data"
/* other studio properties ... */>
</ag-studio>
this.data = {
sources: [{
fields: [{
id: 'salePrice',
options: {
format: new Intl.NumberFormat(undefined, {
style: 'currency',
currency: 'USD',
currencyDisplay: 'narrowSymbol',
maximumFractionDigits: 2,
}),
},
// other field properties
}]
// other source properties
}],
};The following Format properties can be set directly on the field definition:
Optional. How the field values will be serialized into state. Defaults to format serializer. |
Optional. How the field values will be deserialized from state. Defaults to format deserializer. |
Optional. How the field values will be displayed. Defaults to format value formatter. |
Optional. How blank values will be displayed. Defaults to format blank value. |
Optional. Will be passed to the value formatter. |
Providing Custom Formats Copy Link
Custom Formats can be created by passing the result of the createFormats function to the formats property of the data sources definition. The custom Formats are set via the additionalTypes property. See the Format API for the list of properties that can be set on a custom Format.
If using Typescript, the custom Formats should be defined within a type that extends AgFormats and passed to the TFormats generic type parameter of the data source and field types, as well as the createFormats function.
interface CustomFormats extends AgFormats {
myCustomFormat: AgFormatDefinition<'number'>;
}
<ag-studio
:data="data"
/* other studio properties ... */>
</ag-studio>
this.data = {
formats: createFormats({
additionalTypes: {
myCustomFormat: {
dataType: 'number',
supportedRoles: ['numeric', 'category'],
supportedAggregations: ['sum'],
serializer: (value) => value,
deserializer: (value) => value,
valueFormatter: ({ value }) => `*${value}*`,
blankValue: '-',
},
},
}),
// sources, etc.
}; Format API Copy Link
Properties available on the AgFormatDefinition<TDataType extends AgDataType = AgDataType, TOptions = any> interface.
The data type. |
How fields of this format can be used within widgets. Ordered by preference. |
The supported aggregations for fields of this format. |
How the field values will be serialized into state. |
How the field values will be deserialized from state. |
How the field values will be displayed. |
How blank values will be displayed. |
Optional. Will be passed to the value formatter. |