I'm a beginner in reactjs. I'm handling material-table (material-table.com) which should be capable of download data with the custom filename with the current timestamp. This can be solved by assigning the desired filename to the property options.exportFileName
in <MaterialTable>
. However, this timestamp will contain time when the page rendered, but I need the timestamp when the export button was clicked.
I was thinking if I can achieve this by calling defaultExportCsv
from the overridden export function after setting the file name like below:
function TableExport({model}) {
const handleExportCsv = () => {
options.exportFileName = 'filename_' + moment().format('YYYY-MM-DDTHHmmss');
// calling defaultExportCsv here
}
return ( <
MaterialTable columns = {
[{
title: 'ID',
field: 'id'
},
{
title: 'Name',
field: 'name'
},
]
}
data = {
model
}
title = "Title"
options = {
{
columnsButton: true,
exportButton: true,
actionsColumnIndex: -1,
exportCsv: handleExportCsv,
}
}
/>
);
}
I'm unable to call defaultExportCsv()
from the handleExportCsv()
, can somebody help me in this regard ?