|
| 1 | +--- |
| 2 | +sidebar_label: export |
| 3 | +title: export |
| 4 | +description: You can learn about the export event in the documentation of the DHTMLX JavaScript Pivot library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Pivot |
| 5 | +--- |
| 6 | + |
| 7 | +# export |
| 8 | + |
| 9 | +### Description |
| 10 | + |
| 11 | +@short: Fires when exporting data |
| 12 | + |
| 13 | +To trigger the Table event, it's necessary to get access to the Table instance inside Pivot via the [`getTable`](/api/methods/gettable-method) method. |
| 14 | + |
| 15 | +### Usage |
| 16 | + |
| 17 | +```jsx |
| 18 | +"export": ({ |
| 19 | + options: { |
| 20 | + format: "csv" | "xlsx", |
| 21 | + fileName?: string, |
| 22 | + header?: boolean, |
| 23 | + footer?: boolean, |
| 24 | + download?: boolean, |
| 25 | + |
| 26 | + /* XLSX settings*/ |
| 27 | + styles?: boolean | { |
| 28 | + header?: { |
| 29 | + fontWeight?: "bold", |
| 30 | + color?: string, |
| 31 | + background?: string, |
| 32 | + align?: "left"|"right"|"center", |
| 33 | + borderBottom?: string, |
| 34 | + borderRight?: string, |
| 35 | + } |
| 36 | + lastHeaderCell?: { /* same as header */ }, |
| 37 | + cell?: { /* same as header */ }; |
| 38 | + firstFooterCell?: { /* same as header */ }, |
| 39 | + footer?: {/* same as header */}, |
| 40 | + } |
| 41 | + cellTemplate?: (value: any, row: any, column: object ) |
| 42 | + => string | null, |
| 43 | + headerCellTemplate?: (text: string, cell: object, column: object, type: "header"| "footer") |
| 44 | + => string | null, |
| 45 | + cellStyle?: (value: any, row: any, column: object) |
| 46 | + => { format: string; align: "left"|"right"|"center" } | null, |
| 47 | + headerCellStyle?: (text: string, cell: object, column: object, type: "header"| "footer") |
| 48 | + => { format: string; align: "left"|"right"|"center" } | null, |
| 49 | + sheetName?: string, |
| 50 | + |
| 51 | + /* CSV settings */ |
| 52 | + rows: string, |
| 53 | + cols: string, |
| 54 | + }, |
| 55 | + result?: any, |
| 56 | +}) => boolean|void; |
| 57 | +``` |
| 58 | + |
| 59 | +The `export` action of the Table widget has the next parameters that you can configure to your needs: |
| 60 | + |
| 61 | +- `options` - an object with the export options; options differ depending on the format type |
| 62 | +- `result` - the result of the exported Excel or CSV data (usually Blob or file depending on the `download` option) |
| 63 | + |
| 64 | + **Common options for both formats ("csv" "xlsx" ):** |
| 65 | + |
| 66 | + - `format` (string) - (optional) the export format that can be "csv" or "xlsx" |
| 67 | + - `fileName` (string) - (optional) a file name ("data" by default) |
| 68 | + - `header` (boolean) - (optional) defines if a header should be exported (**true** by default) |
| 69 | + - `footer` (boolean) - (optional) defines if a footer should be exported (**true** by default) |
| 70 | + - `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 as `ev.result` |
| 71 | + |
| 72 | + **Options specific for "xlsx" format:** |
| 73 | + |
| 74 | + - `sheetName` (string) - a name of Excel sheet ( "data" by default) |
| 75 | + - `styles` (boolean or object) - if set to **false**, grid will be exported without any styling; can be configured using a hash of style properties: |
| 76 | + - `header` - an object with the next settings for header cells: |
| 77 | + - `fontWeight` (string) - (optional) can be set to "bold" or if not set, the font will be normal |
| 78 | + - `color` (string) - (optional) text color in header |
| 79 | + - `background` (string) - (optional) background color for header |
| 80 | + - `align` - (optional) text alignment that can be "left"|"right"|"center". If not set, alignment set in Excel will be applied |
| 81 | + - `borderBottom` (string) - (optional) the style of the bottom border |
| 82 | + - `borderRight` (string) - (optional) the style of the right border (e.g., *borderRight: "0.5px solid #dfdfdf"* ) |
| 83 | + - `lastHeaderCell` - style properties for the last row of header cells. Properties are the same as for *header* |
| 84 | + - `cell` - style properties for body cells.Properties are the same as for *header* |
| 85 | + - `firstFooterCell` - style properties for the first row of footer cells. Properties are the same as for *header* |
| 86 | + - `footer` - style properties for footer cells. Properties are the same as for *header* |
| 87 | + - `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 exported |
| 88 | + - `headerCellTemplate` - 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 values |
| 89 | + - `cellStyle` - 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) |
| 90 | + - `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 |
| 91 | + :::note |
| 92 | + By default, for the "xlsx" format, date and number fields are exported as raw values with default format or the format defined via the [`fields`](/api/config/fields-property) property. But if a template is defined for a field (see the [`tableShape`](/api/config/tableshape-property) property), it exports the rendered value defined by that template. In case both the template and `format` are set, the template settings will override the format ones. |
| 93 | + ::: |
| 94 | + |
| 95 | + **Options specific for "csv" format:** |
| 96 | + |
| 97 | + - `rows` (string) - (optional) rows delimiter, "\n" by default |
| 98 | + - `cols` (string) - (optional) columns delimiter, "\t" by default |
| 99 | + |
| 100 | +## Example |
| 101 | + |
| 102 | +In this snippet you can see how to export data: |
| 103 | + |
| 104 | +<iframe src="https://snippet.dhtmlx.com/zjuloqxd?mode=result" frameborder="0" class="snippet_iframe" width="100%" height="600"></iframe> |
| 105 | + |
| 106 | +**Related articles**: |
| 107 | +- [`getTable`](/api/methods/gettable-method) |
| 108 | +- [Exporting data](/guides/exporting-data) |
| 109 | +- [Date formatting](/guides/localization#date-formatting) |
| 110 | + |
0 commit comments