export
Description
Fires when exporting data
To trigger the Table event, it's necessary to get access to the Table instance inside Pivot via the getTable
method.
Usage
"export": ({
options: {
format: "csv" | "xlsx",
fileName?: string,
header?: boolean,
footer?: boolean,
download?: boolean,
/* XLSX settings*/
styles?: boolean | {
header?: {
fontWeight?: "bold",
color?: string,
background?: string,
align?: "left"|"right"|"center",
borderBottom?: string,
borderRight?: string,
}
lastHeaderCell?: { /* same as header */ },
cell?: { /* same as header */ };
firstFooterCell?: { /* same as header */ },
footer?: {/* same as header */},
}
cellTemplate?: (value: any, row: any, column: object )
=> string | null,
headerCellTemplate?: (text: string, cell: object, column: object, type: "header"| "footer")
=> string | null,
cellStyle?: (value: any, row: any, column: object)
=> { format: string; align: "left"|"right"|"center" } | null,
headerCellStyle?: (text: string, cell: object, column: object, type: "header"| "footer")
=> { format: string; align: "left"|"right"|"center" } | null,
sheetName?: string,
/* CSV settings */
rows: string,
cols: string,
},
result?: any,
}) => boolean|void;
The export
action of the Table widget has the next parameters that you can configure to your needs:
-
options
- an object with the export options; options differ depending on the format type -
result
- the result of the exported Excel or CSV data (usually Blob or file depending on thedownload
option)Common options for both formats ("csv" "xlsx" ):
format
(string) - (optional) the export format that can be "csv" or "xlsx"fileName
(string) - (optional) a file name ("data" by default)header
(boolean) - (optional) defines if a header should be exported (true by default)footer
(boolean) - (optional) defines if a footer should be exported (true by default)download
(boolean) - (optional) defines whether to download a file. true is set by default. If set to false, the file will not be downloaded, Excel or CSV data (Blob) will be available asev.result
Options specific for "xlsx" format:
sheetName
(string) - a name of Excel sheet ( "data" by default)styles
(boolean or object) - if set to false, grid will be exported without any styling; can be configured using a hash of style properties:header
- an object with the next settings for header cells:fontWeight
(string) - (optional) can be set to "bold" or if not set, the font will be normalcolor
(string) - (optional) text color in headerbackground
(string) - (optional) background color for headeralign
- (optional) text alignment that can be "left"|"right"|"center". If not set, alignment set in Excel will be appliedborderBottom
(string) - (optional) the style of the bottom borderborderRight
(string) - (optional) the style of the right border (e.g., borderRight: "0.5px solid #dfdfdf" )
lastHeaderCell
- style properties for the last row of header cells. Properties are the same as for headercell
- style properties for body cells.Properties are the same as for headerfirstFooterCell
- style properties for the first row of footer cells. Properties are the same as for headerfooter
- style properties for footer cells. Properties are the same as for header
cellTemplate
- a function to customize the export value of each cell. It takes the value, row, and column objects as parameters and returns the custom value to be exportedheaderCellTemplate
- a function that customizes the value of a header or footer cell during export. It is called with the text, header cell object, column object, and cell type ("header" or "footer"). This allows users to modify the exported header/footer valuescellStyle
- a function that allows customizing the style and format of individual cells during export. It takes the value, row, and column objects as parameters and should return an object with style properties (e.g., alignment or format)headerCellStyle
- similar to cellStyle, but specifically for the header and footer cells. This function takes the text, header cell object, column object, and type ("header" or "footer") and returns style properties
noteBy default, for the "xlsx" format, date and number fields are exported as raw values with default format or the format defined via the
fields
property. But if a template is defined for a field (see thetableShape
property), it exports the rendered value defined by that template. In case both the template andformat
are set, the template settings will override the format ones.Options specific for "csv" format:
rows
(string) - (optional) rows delimiter, "\n" by defaultcols
(string) - (optional) columns delimiter, "\t" by default
Example
In this snippet you can see how to export data:
Related articles: