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, Columns
  • exportDateFormat - 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
Format of exported data
Formatting Report Values
Fork
  • 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:
    • Language column is in upper case
    • Created and Pushed columns have a format of 'yyyyMMdd'
    • All numeric columns display 8 digits
Try It Out

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

string
Custom format for exporting Date columns

AdapTable exports all dates in the custom format provided, irrespective of how they are formatted in AG Grid.

Note

  • The exportDateFormat property has higher precedence than exportDataFormat
  • It will be applied to all exported Date columns (including if the column has a valueFormatter)
Formatting Dates in Reports
Fork
  • This demo illustrates how to use the exportDateFormat property in Export Options to override any formatted dates:
    • The Created and Pushed columns have a Display Format of 'yyyyMMdd'
    • The Updated Column has no Display Format
  • We have set exportDateFormat to 'yyyy-dd-MM'
  • This takes precedence over the formats used in AG Grid (even though we also set exportDataFormat to be formattedValue)
Try It Out
  • Export the data from the Grid and notice that the Language column keeps the format it was given in Initial State (since we export display values)
  • But the date columns all use the format giving in Export Options, overriding what is displayed in AG Grid and what formats they have been given