Mui-datatables: On download CSV trigger aditional function

Created on 18 Jan 2019  路  4Comments  路  Source: gregnb/mui-datatables

For business rules, every time a user dowloads a CSV from a table, I need to record it in an rds instance, (just the user and the action, nothing about the file details or anything like that), so I was wondering if is it possible to trigger an aditional function when the user clicks in the download button.

Couldn't find anything usefull on the docs, nor in the issues. Thanks in advance

Most helpful comment

I'm wanting an option for downloading all the data from the server instead of just the data on the page. And my data contains @material-ui/core/List components and these show up as [object Object] in the downloaded csv file.

All 4 comments

I'm proposing a new callback named onCSVDownload that would trigger when a user clicks the CSV download

Could we also manipulate the data that goes to the CSV? Or, simpler, choose to have the input data go to the CSV instead of the rendered data?
I have columns for memory where I render 2048 into 2,048 MB and my clients would like to have a CSV without the commas or letters

EDIT: It actually seems like my columns where I translate with commas / MB don't get exported as such. But I have columns which are rendered as more than just text (I pass in a <Typography> or a <LinearProgress> sometimes) and those end up in the excel as [object Object]

I'm wanting an option for downloading all the data from the server instead of just the data on the page. And my data contains @material-ui/core/List components and these show up as [object Object] in the downloaded csv file.

Don't know if is the best or the desirable approach, but I made my own event, bind it in an IconButton onClick event and put it in the options customToolbar. Like this:

customToolbar: () => { return (<IconButton aria-label="download" onClick={() => this.handleDownload(this.state.data)}> <CloudDownload/> </IconButton> </Tooltip>) }

It looks like is part of the toolbar and does what is expected to. Only disadvantage is that you have to make download csv logic from scratch.

Hope it helps

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harryluo91 picture harryluo91  路  3Comments

pranavtheway picture pranavtheway  路  3Comments

T-pirithiviraj picture T-pirithiviraj  路  3Comments

JordanKadish picture JordanKadish  路  4Comments

chapmanjacobd picture chapmanjacobd  路  4Comments