Hi,
I have a problem with the customize function for the csv export.
Actually I have a page on my website where you can specify the csv export config (date format, decimal format, field separator, field boundary, etc.), so first I retreive this data, then I process the default csv string to match my config, by changing the field separator etc.
The processing works well, my custom csv is properly formatted.
Here is the code I use for the buttons :
buttons: [
{
extend: 'csv',
filename: 'datatables_csv',
customize: async function(csv)
{
const customCSV = await defaultCSVBuilder(csv);
console.log(customCSV);
return customCSV;
}
}
]
As you can see I pass the default csv string to my custom csv builder to make some processing. Howerver when I open the downloaded csv, the content is : [object Promise]
I don't understand why despite using async / await the promise doesn't seem to resolve. So I put one await sleep(5sec) inside my custom function, before the end, and as soon as I clicked the download button, the file was downloaded, then 5 seconds later my custom csv file was displayed in the console. So it seems that customize() is not waiting for my custom function to resolve.
I don't feel like I have made a mistake but there is probably something that I don't understand, your help is welcome!
(I based my custom function on the comment on this page : https://datatables.net/reference/button/csv)