Any Export Complete Event?
Any Export Complete Event?
Hi, I have created a custom action under the buttons for exporting either CSV/Excel files. The export takes quite a bit of time so I have added a loading modal to notify the user - however, I am looking for a way to detect when the export is complete.
If there is some type of event that is fired so I can attach an event listener and have it close the modal once export has completed, that would be great! I have also (unsuccessfully) tried to implement some sort of callback function or promise, however it simply executes the code immediately every time and does not wait for the export to finish.
Replies
The
buttons-processing
might do what you want.Kevin
What Kevin said . Check for the
indicator
parameter beingfalse
to see when the processing is complete.Allan
Thank you, I will try that out and let you know if it works!
Hello, after implementing and testing it, it doesn't seem like the Datatables Export File functions (csv/html) are firing any buttons-processing events.
I have checked to see if the handler is receiving any fired events when I click the export buttons- however, they are not.
Manually adding processing(true/false) in the buttons custom action will not resolve my problem since the issue is that the next line of code immediately executes even before the export has completed
Here is some sample code to show what I mean:
action: function(e, dt, button, config) {
The final line immediately executes after the export line begins, it does not wait for the export to finish.
I need some type of way to detect when either the export is complete or an exported file has been downloaded, so then the modal will be successfully hidden at the proper time.
The
buttons-processing
works in this example:http://live.datatables.net/powoseza/1/edit
Basically used the example in the docs but changed to console.log output.
Maybe you can update my example to show the issue you are having.
Kevin
Kevin,
I implemented a very similar version as your example. For some reason, it still does not work.
Could this be an issue regarding the version? I am using DataTables 1.10.18
According to the
buttons-processing
documentation the feature was introduced into Buttons 1.5.7.Kevin
@kthorngren
Hi Kevin,
I saw your example above and yes, it works.
I have a simple Data Table that contains a more complex Excel export that can take a while. Hence I wanted to display a message informing the user or display a spinner while making the Excel file.
I use sweet alert or busyLoad for these purposes. It turned out that with "buttons-processing" they aren't working. They don't get triggered. The only thing I got working - like in your example - was console.log and a simple alert.
Do you have any idea why plugins don't get triggered only "native" Javascript? I have never come across this behavior with other Data Table events.
This is my code:
Using this plugin it does not work:
CSS:
Javascript:
It should work but nothing happens; only works with native Javascript alert:
I updated the above example with Sweet Alert and it seems to work. The export is quick so its just a flash on the screen. I've not used it before I'll need to check it out.
http://live.datatables.net/powoseza/19/edit
Not sure why its not working in your case. Do you get errors in your browser's console?
Kevin
Thanks Kevin!
No errors in the console, All fine.
Just took a look at your example - and I guess I know what the problem is:
Sweet Alert seems to get triggered on "mouseup" which doesn't happen for a lengthy Excel export until it is (almost) finished.Hence you only see it flashing briefly at the end which is completely useless. Same with "busyLoad" ...
Actually I don't know why "mouseup" isn't happening for so long. I mean: Even if it takes a while to process something the button should not look "clicked" for such a long time?! (I am not a good front end programmer, sorry!)
The simple Javascript alert seems to get triggered on "mousedown". That's why it works and the other solutions don't .
Do you think this can be changed? Many thanks for your generous help, Kevin!
Thought about it again. I use Sweet Alert and busyLoad a lot when I do ajax calls etc. If this is in conjunction with clicks on buttons the buttons only look "clicked" really briefly because nothing much is happening in the browser / the front end.
While with the Excel export a lot of processing is happening on the client machine - and the button doesn't look "clicked" only briefly but doesn't go up until the front end processing has finished.
This seems to be the issue here. ... and how can we change this.
I think what might be happening here is that the sweetalart is queued for display in the browser's renderer, but it buffers changes to try and make as few as possible (performance). Because a timeout can happen and the DOM update happens the export is triggered, resulting is the browser continuing to delay the redraw.
Let's try a custom button that does the display of sweetalert and makes use of the default Excel export button in a small timeout:
You'll need to add the code for showing and hiding sweetalert.
Allan
Hi Allan,
thank you! I tried it but it didn't work:
- Sweet Alert was never hidden
- Nothing got downloaded
I also tried it with the confirm button and a subsequent spinner: Didn't work either. I reversed to my solution using a simple Java Script alert.
Roland
It is actually the timout that causes nothing to be downloaded. I removed everything else to test it. With the timeout: no download. Without the timeout it works.
My use case is presenting the log to some expert users highlighting all of the changes made over time in the Excel export. To do this all with the log table (according to your blog example) is somewhat heavy lifting. My users can change the time to be shown using a button. On button click I do this ... and the use of "busyLoad" in this example would be exactly what I need for the Excel export as well:
Oops - I should have uses a fat arrow function to preserve the context
If that doesn't work, I'd need a link to a test case showing the problem.
Allan
Works!
And no need for the buttons-processing event any longer.
The only downside: Doesn't work with IE and polyfills don't help with it. Tried to rewrite it but couldn't make it work. Solution: IE users don't see the respective menu items ...
should work in legacy browser.
Allan
Thanks! That is really helpful. It works! (But IE is so slow with this I'll keep it blocked for those menu items.)
Hello!
I'm trying this on SPFx and $.fn.dataTable.ext.buttons.excelHtml5 is not exists.
index.ts from @types/datatables.net-buttons do not have excelHtml5, it's has csvHtml5 instead.
Is any possiblity that @types/datatables.net-buttons will be updated?
interface ExtButtonsSettings {
collection: ExtButtonsCollectionSettings;
csvHtml5: ButtonSettings;
}
You would probably need to send a pull request to DefinitelyTyped for that. We maintain our own typings for Buttons.
Allan