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

Set a filename when using CSVDownload #47

Open
cmdalbem opened this issue Dec 19, 2017 · 17 comments
Open

Set a filename when using CSVDownload #47

cmdalbem opened this issue Dec 19, 2017 · 17 comments

Comments

@cmdalbem
Copy link

The filename prop allows to set a custom filename to the CSV file, however it's available only when using the CSVLink component. Would be interesting to be able set a filename when using the CSVDownload component as well.

@rlyle
Copy link

rlyle commented Jan 15, 2018

Yes, please on this feature..

@junbinku
Copy link

junbinku commented Jun 1, 2018

Is this feature still ongoing?

@iorabi
Copy link

iorabi commented Jun 4, 2018

@abdennour will #69 resolve this? if so, when can this be merged.

@Lyncee59
Copy link

Lyncee59 commented Jun 6, 2018

+1 on this feature too, really need to be able to set a filename !

@davecat
Copy link

davecat commented Jun 7, 2018

is not work

@davecat
Copy link

davecat commented Jun 7, 2018

But I found a correct way, you can use replace. example:
<CSVlink filename='name' data='data'> <div /> <CSVlink>
simulation this div click.

@KasparasK
Copy link

+1 on this feature

@chris-burkhardt
Copy link

This still doesn't work. Why wouldn't you have this feature on CSVDownload when you have it CSVLink? 2 years and still open? Please add it as a feature. 🙏

@RTurek
Copy link

RTurek commented Mar 12, 2020

Can a maintainer update and merge #137 to fix this please?

@immanuelf9
Copy link

Here is a way around this issue by using refs. https://stackoverflow.com/questions/53504924/reactjs-download-csv-file-on-button-click

@dimdog
Copy link

dimdog commented Apr 30, 2021

I ended up copying "core" from the lib as "Core.js" and writing:

import React, { useEffect, useRef, useState } from 'react';
import {buildURI} from './Core';

export const CSVDownload = (props) => {
    const urlRef = useRef();
    const [url, setUrl] = useState("");
    useEffect(() => {
        setUrl(buildURI(props.data));
    }, [])
    useEffect(() => {
        if (url.length >0){
            urlRef.current.link.click()
        }
    }, [url]);

    return <a href={url} download={props.filename} ref={urlRef} />;
} 

Works exactly as expected.

@tamlyn
Copy link

tamlyn commented Jun 11, 2021

Here's another drop-in replacement for CSVDownload thats supports filename and uses only CSVLink:

import React, { useEffect, useRef } from 'react'
import { CSVLink } from 'react-csv'
const CSVDownload = (props) => {
  const btnRef = useRef(null)
  useEffect(() => btnRef.current?.click(), [btnRef])
  return (
    <CSVLink {...props}>
      <span ref={btnRef} />
    </CSVLink>
  )
}

@williams335
Copy link

This can help to solve the problem:
#72 (comment)

@dhanushkakp
Copy link

Is there any solution for this? This issue has open in 2017!!

@chris-burkhardt
Copy link

@dhanushkakp I could not find a solution either so I created my own CSV Download functionality here: https://gist.github.com/cburkhardtBB/14ba0e3a37c2cef83eaea79e8c93092d

It supports headers/no headers, file naming based on time, and is all done in less than 100 lines of code.

@solarstar101
Copy link

abandoned?

@ChrisRey-C
Copy link

This workaround worked #47 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests