Skip to content

Commit

Permalink
new update with title. (#386)
Browse files Browse the repository at this point in the history
* new update with title

* new update with title, fixed error in index

* Update .gitignore

* Update README.md

* Update csv.ts

* Update csv.ts

---------

Co-authored-by: Sagar Sajeev <[email protected]>
  • Loading branch information
centrric-cntc0006 and sagarcentrric authored Jan 6, 2024
1 parent e562a1f commit cdc9a78
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ You can also use the columns definition to set the columns display order
| disabled | boolean | false | false | If `true` the download process is blocked. |
| meta | boolean | false | false | If `true` the downloaded file will contain meta instruction sep to help microsoft excel and open office to recognize the sepator character. |
| handleError | function | undefined | false | Function to be invoked on error data |
| handleEmpty | function | undefined | false | Function to be invoked on empty result data |
| handleEmpty | function | undefined | false | Function to be invoked on empty result data
| title | string | undefined | false | You can pass a string to be added as a title at the top of the sheet

All other props are passed to button or wrapping component.

Expand Down
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
5 changes: 5 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,9 @@ export default async function csv({
if (!noHeader) {
const headerNames = order.map((id) => map[id])
if (headerNames.length > 0) {
if (title !== '') {
content.push(title)
}
content.push(headerNames.map(wrap).join(separator))
}
}
Expand Down

0 comments on commit cdc9a78

Please sign in to comment.