×

Tabulator Download

K8 forms

Tabulator creates excellent tables and provides several download formats. I use the following download formats:

  • csv: CSV Format (downloads the rows)
  • xlsx: Excel Format (downloads groups and sum)
  • pdf: PDF Format

Tabulator exports the raw data. I show you here some easy ways for a good formatting.

Sorry, this document is only in english available.

Example

Depending on your browser you will get the english or german formats of number and datetime.

With you open the dropdown and choose options:

  • utf-8 CSV Export
  • Excel Export
  • PDF Export

The control columns have the property: downlad:false. They are not downloaded. Only the visible columns are dowonloaded.

Download problems and solutions

This are the download problems and solutions:

  • Null values should be displayed as blank or 0
    • solution: accessor function:
      • for non numeric columns returning ‘‘
      • for numeric colums returning 0
  • countries with decimal komma
    • xlsx: its not possible to calculate with numbers in the excelsheet
      • solution: accessor function returning number(value)
    • csv:
      • field delimiters are changed to ';'
      • special caracters (ÄÖÜ,…) are well formatted with bom: true
      • decimal numbers has to be transformed to decimal komma
    • pdf:
      • date format like in tabulator
      • number with decimal point and decimals like in tabulator
      • alignement to right
  • accessor functions can not appended in Json file. They have to be appended in in JavaScript

Look in the following description to get a better download result.

Prepare page head

Declare the following libraries and variables in your page head.

Attention Please refer to the tabulator documents to implent the right jsPDF and autotable table version corresponding to your tabulator version!

Accessor: k8tabulator.accessor(...)

k8tabulator.accessor uses the tabulator column formatter and formatterParams. It support the formatter 'datetime' and 'money'. For formatting the value, the k8formatter object is used (origin tabulator).

Append the accessor to the columns

In webkitthe function nestedLoop() append on all tabulator columns ths accessor function, if this is not already set.

k8formatter (source tabulator)

The k8formatter is copied out of the tabulator formatting function. It supports formatting for:

  • money
  • datetime

Download event

Before calling the „download“ method the variable: tabulator_export is set to „csv“, „xlsx“ or „pdf“

CSV Format

Depending on the decimal sign the delimiter is set to ';' or ','.

Excel Format

The decimal sign is set to point or komma.

PDF Format

The ColumnStyles object is created:

  • "0":
    • halign: right
    • width: 100
  • "1": ...

For each colum the alignement and width is set. The width is important for columns with large content. Without width definition of all columns, the column with large content would be enlarged too much.

References

More informations to tabulator and libraries: