Formatting Report Data
Summary
- AdapTable provides a range of options to allow developers to configure how report data is formatted
- These include choosing whether to export the "display" (rather than "raw") value of the cell
- Additionally Dates can be given a bespoke format
AdapTable allows developers to configure how the data in exported Reports is formatted.
These is done via 2 (similar-sounding) properties in Export Options:
exportDataFormat- use the Display Value (instead of the Raw Value) - for all, or a subset of, ColumnsexportDateFormat- provides a bespoke export format for Date columns
Hint
See Processing Reports for an even more fine-grained approach, where the exported values can also be changed
Display Values
By default AdapTable exports the underlying raw data in AG Grid.
Note
- A value of 12.59 which has been formatted as "£12.59 (GBP)" will have the raw value sent to Excel
- This means that it can be identified as a number and treated accordingly
This is by design: AdapTable provides a data export function not a WYSIWYG operation.
Hint
The sole exception is when using the VisualExcel Report Format Type which always and only exports Display Values
If this behaviour is not wanted, it can be changed using the exportDataFormat property in Export Options.
This property allows you configuring exporting using the Display Value for:
- All Columns in all exports
- by Column Data Type (i.e. different rules for string, number and date Columns)
- on a per-Column basis (by using a function)
exportDataFormat
Default: 'rawValue'DataFormatType | DataFormatDataType- In this demo we set up export-formatting in Export Options to export the formatted (i.e. display) cell value rather than the underlying value
- We have set 3 Display Formats in the Grid and in each case the display value is exported:
Languagecolumn is in upper caseCreatedandPushedcolumns have a format of 'yyyyMMdd'- All
numericcolumns display 8 digits
Run a Report and notice that the Language, Created, Pushed and numeric columns keep the Display Format they were given in Initial State
Formatting Dates
Dates can offer additional complexity in terms of formatting export data.
It is not unusual that a user will want to export a date differently both to the raw value and to its display value.
For this reason AdapTable provides the exportDateFormat property in Export Options.
exportDateFormat
stringAdapTable exports all dates in the custom format provided, irrespective of how they are formatted in AG Grid.
Note
- The
exportDateFormatproperty has higher precedence thanexportDataFormat - It will be applied to all exported Date columns (including if the column has a valueFormatter)
- This demo illustrates how to use the
exportDateFormatproperty in Export Options to override any formatted dates:- The
Createdand Pushed columns have a Display Format of 'yyyyMMdd' - The
UpdatedColumn has no Display Format
- The
- We have set
exportDateFormatto 'yyyy-dd-MM' - This takes precedence over the formats used in AG Grid (even though we also set
exportDataFormatto be formattedValue)
- Export the data from the Grid and notice that the
Languagecolumn keeps the format it was given in Initial State (since we export display values) - But the
datecolumns all use the format giving in Export Options, overriding what is displayed in AG Grid and what formats they have been given