-
-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading JSZip and PDFMake scripts dynamically #43
Comments
Hi, Yes that is absolutely possible. The way the scripts operate at the moment doesn't allow for that, but I don't see any reason why, either new buttons could be created that will perform that action, or the existing ones modified. The only one thing that makes me hesitant about this is that creating and download a file can sometimes (possibly older browsers - I can't remember off the top of my head) only be triggered from a user interaction. If an async delay is introduced while waiting for a library to be loaded, then the result would not longer be due to user interaction (at least as the browser sees it). I'd also be very reluctant to add a dependancy (for example RequireJS which could be used to resolve this) to Buttons or to hard code paths into it (even if they could be modified as configuration options). The other point to consider is that the client-side file creation inherently has limitations. Performance for large pdfs is really poor for example and old legacy browsers can't create files beyond a certain size (current browsers as well, but the limits are huge). So server-side creation of these files might increasingly be attractive to address the client library size + the concerns above. |
Thanks for so fast and detailed answer Allan! If you say that it's technically possible, I think I'll try to implement it (maybe using |
Yes. It might be that it is a good option to provide the ability to load those libraries dynamically in the built in buttons if it can be done with only a small amount of code and in an understandable way (i.e. won't confuse the average developer). Another option is to provide these buttons as plug-ins. Certainly interested to see what you cook up! |
I tried to implement it. My general conception is the following
But unfortunately I haven't found any public functions for exporting data.
Is it possible to make export methods public without major code rewrite? Or maybe it's not a good idea actually? |
You are correct - there isn't a public function for this as I hadn't expected anything other than my built in buttons to require that code. At the moment, I think the only way to make this work would probably be to modify the library code. I'm trying to think of a way that you could access the functionality that Buttons has internally - it might be possible to extend the the |
I tried my hand at this problem with webpack. I'll be very interested to see if we get any browsers throwing file download errors thinking it's not being caused by the user.
I felt okayish doing
I did the same thing with JSZip for excel exporting. The only difference in the two cases is a module system thing, but I'll mention it anyways. pdfMake straps itself to the window always. JSZip, if being used by a module loader, exports itself and you need to put it on the window for DataTables to find it.
|
Really - nice. Thanks for sharing this with us! |
Thanks for sharing it @michaeldjeffrey! Allan's idea and your implementation of it with work well without webpack:
So maybe I can close this issue now |
@DataTables, as all we know and as you say "the disadvantage is that these files can significantly increase the amount of Javascript required on your page". It's not a good idea to load extra 500 kB library if it's not used everyday. And it's the only reason that stops me (and many other developers I think) from using it. Is it possible to load these libraries dynamically, only when user clicks "Export to PDF"/"Export to Excel" button for example? I'm not asking for solutions (code examples) here. I'm asking just about a possibility of that. And what do you think about this idea in general?
The text was updated successfully, but these errors were encountered: