fix download csv
This commit is contained in:
parent
0fbb1b6f4c
commit
2c78f61e2e
|
@ -34,6 +34,7 @@ This web part provides easy way to render SharePoint custom list in datatable vi
|
||||||
Solution|Author(s)
|
Solution|Author(s)
|
||||||
--------|---------
|
--------|---------
|
||||||
react-datatable | Chandani Prajapati ([@Chandani_SPD](https://twitter.com/Chandani_SPD))
|
react-datatable | Chandani Prajapati ([@Chandani_SPD](https://twitter.com/Chandani_SPD))
|
||||||
|
react-datatable | Abderahman Moujahid
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ Version|Date|Comments
|
||||||
1.3|March 31,2021| Changed UI as per SharePoint list, Set themeing as per current SharePoint site theme, Created custom pagination by using reusable controls, Added features to export CSV based on the filter if the filter is available, Added hyperlink feature for image and link column in export to pdf and also set alternative row formatting in generated pdf as per property pane configuration odd/even row color, fixed object issue (for people/hyperlink, etc) in export to CSV.
|
1.3|March 31,2021| Changed UI as per SharePoint list, Set themeing as per current SharePoint site theme, Created custom pagination by using reusable controls, Added features to export CSV based on the filter if the filter is available, Added hyperlink feature for image and link column in export to pdf and also set alternative row formatting in generated pdf as per property pane configuration odd/even row color, fixed object issue (for people/hyperlink, etc) in export to CSV.
|
||||||
1.4|April 10, 2021|Added feature to show profile picture in user column and shows display name of user field in export to CSV and PDF.
|
1.4|April 10, 2021|Added feature to show profile picture in user column and shows display name of user field in export to CSV and PDF.
|
||||||
1.5|June 2, 2021|Added feature to show image in dataTable and upgraded to the SPFx version 1.12.1.
|
1.5|June 2, 2021|Added feature to show image in dataTable and upgraded to the SPFx version 1.12.1.
|
||||||
|
1.6|July 16, 2021|Changed library export-to-csv with react-csv
|
||||||
|
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "react-datatable",
|
"name": "react-datatable",
|
||||||
"version": "1.5.0",
|
"version": "1.6.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
@ -22,10 +22,10 @@
|
||||||
"@pnp/sp": "2.5.0",
|
"@pnp/sp": "2.5.0",
|
||||||
"@pnp/spfx-controls-react": "3.1.0",
|
"@pnp/spfx-controls-react": "3.1.0",
|
||||||
"@pnp/spfx-property-controls": "^3.2.0-beta.ab74df5",
|
"@pnp/spfx-property-controls": "^3.2.0-beta.ab74df5",
|
||||||
"export-to-csv": "^0.2.1",
|
|
||||||
"office-ui-fabric-react": "7.156.0",
|
"office-ui-fabric-react": "7.156.0",
|
||||||
"pdfmake": "^0.1.70",
|
"pdfmake": "^0.1.70",
|
||||||
"react": "16.9.0",
|
"react": "16.9.0",
|
||||||
|
"react-csv": "^2.0.3",
|
||||||
"react-dom": "16.9.0"
|
"react-dom": "16.9.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -1,47 +1,27 @@
|
||||||
import * as React from 'react';
|
import * as React from "react";
|
||||||
import * as strings from 'ReactDatatableWebPartStrings';
|
import * as strings from "ReactDatatableWebPartStrings";
|
||||||
import { ExportToCsv } from 'export-to-csv';
|
import { CSVLink } from "react-csv";
|
||||||
import { IIconProps, PrimaryButton } from 'office-ui-fabric-react';
|
import { IIconProps, PrimaryButton } from "office-ui-fabric-react";
|
||||||
import styles from './ExportListItemsToCSV.module.scss';
|
import styles from "./ExportListItemsToCSV.module.scss";
|
||||||
interface IExportToCSV {
|
interface IExportToCSV {
|
||||||
columnHeader: Array<string>;
|
columnHeader: Array<string>;
|
||||||
listName: string;
|
listName: string;
|
||||||
description: string;
|
description: string;
|
||||||
dataSource: ()=> any[];
|
dataSource: () => any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExportListItemsToCSV(props: IExportToCSV) {
|
export function ExportListItemsToCSV(props: IExportToCSV) {
|
||||||
|
const downloadIcon: IIconProps = { iconName: "Download" };
|
||||||
|
|
||||||
const downloadIcon: IIconProps = { iconName: 'Download' };
|
let { listName, dataSource } = props;
|
||||||
|
|
||||||
let { columnHeader, listName, dataSource } = props;
|
return (
|
||||||
|
<CSVLink data={dataSource()} filename={`${listName}.csv`}>
|
||||||
function generateCSV() {
|
<PrimaryButton
|
||||||
|
text={strings.DownloadAsCSVLabel}
|
||||||
let colHeader = columnHeader;
|
iconProps={downloadIcon}
|
||||||
const options = {
|
className={styles.btnCSV}
|
||||||
filename: listName,
|
/>
|
||||||
fieldSeparator: ',',
|
</CSVLink>
|
||||||
quoteStrings: '"',
|
);
|
||||||
decimalSeparator: '.',
|
}
|
||||||
showLabels: true,
|
|
||||||
showTitle: true,
|
|
||||||
title: '',
|
|
||||||
useTextFile: false,
|
|
||||||
useBom: true,
|
|
||||||
useKeysAsHeaders: true,
|
|
||||||
headers: colHeader
|
|
||||||
};
|
|
||||||
const csvExporter = new ExportToCsv(options);
|
|
||||||
csvExporter.generateCsv(dataSource());
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PrimaryButton
|
|
||||||
text={strings.DownloadAsCSVLabel}
|
|
||||||
iconProps={downloadIcon}
|
|
||||||
onClick={() => generateCSV()}
|
|
||||||
className={styles.btnCSV}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue