Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to add title at top of the csv #386

Merged
merged 7 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
node_modules/
dist/
example/package-lock.json
example/node_modules/
dolezel marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ function App() {
text="Using Async Callback to Compute Datas"
/>

<CsvDownloader
filename="myfileWithTitle"
separator=";"
columns={head}
title={'Title for the file'}
datas={asyncComputeDatas}
text="Using Async Callback to Compute Datas with Title"
/>

<CsvDownloader
filename="myfile"
separator=";"
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ICsvDownloadProps
meta?: boolean
handleError?: (err: unknown) => void
handleEmpty?: () => void
title?: string
}

export default class CsvDownload extends React.Component<ICsvDownloadProps> {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface ICsvProps {
wrapColumnChar?: string
newLineAtEnd?: boolean
chunkSize?: number
title?: string
}

export default async function csv({
Expand All @@ -117,6 +118,7 @@ export default async function csv({
wrapColumnChar = '',
newLineAtEnd = false,
chunkSize = 1000,
title = '',
}: ICsvProps) {
// eslint-disable-next-line no-async-promise-executor
return new Promise<void | string>(async (_resolve, reject) => {
Expand All @@ -136,6 +138,8 @@ export default async function csv({
if (!noHeader) {
const headerNames = order.map((id) => map[id])
if (headerNames.length > 0) {
if(title!=='')
dolezel marked this conversation as resolved.
Show resolved Hide resolved
content.push(title)
content.push(headerNames.map(wrap).join(separator))
}
}
Expand Down
Loading