question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

First fetch data from server then export xlsx file with same click

See original GitHub issue

First I want to fetch data with API then that data should download with react-data-export. For this, I want to use single button for both work.

this time, I’m using like this - <Button onClick={this.fetchData}>Fetch Data</Button>

fetchData() {
  axios.get('api_link')
    .then(({data}) => {
      this.setState({data})
    })
}

and then Download data -

<ExcelFile element={<button>Download Data</button>}>
	<ExcelSheet data={data} name="Employees">
		<ExcelColumn label="Name" value="name"/>
		<ExcelColumn label="Wallet Money" value="amount"/>
		<ExcelColumn label="Gender" value="sex"/>
		<ExcelColumn label="Marital Status" value={(col) => col.is_married ? "Married" : "Single"}/>
	</ExcelSheet>
</ExcelFile>

but Buttons will show 2 times. it’s not good looking for users.

So, How can I fetch and download data with only one click ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
javaGuy33commented, Mar 25, 2021

Hi @arpitprod in your case you can use hideElement property, you can call exactly like above code and it will work.

Hi @securedeveloper, when I am trying to hide the button using ‘hideElement’ property. The excel file is downloading twice. Did you come across such king of issue?

1reaction
thinhnkcommented, Jul 18, 2018

@arpitprod after the first download => set state data = null. That is my trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Export SQL Server Data to an Excel File
In Object Explorer, right-click the required database/table/view and click Export Data on the shortcut menu to invoke the export wizard. On its ...
Read more >
3 Ways To Export an SQL Query to an Excel File using SQL ...
Right-click on the database you want to export from. Then Select tasks and “Export Data”. Export Data. The SQL Server Wizard will startup....
Read more >
How to Import and Export SQL Server data to an Excel file
From the Select the database that contains the data you want drop down box, choose the database from which the data will be...
Read more >
How to save .xlsx data to file as a blob - javascript
Here's my implementation using the fetch api. The server endpoint sends a stream of bytes and the client receives a byte array and...
Read more >
Import from Excel or export to Excel with SSIS - SQL Server ...
Specify Excel as your data source. · Provide the Excel file name and path. · Select the Excel version. · Specify whether the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found