Is it possible to add data in chunks?
Is it possible to add data in chunks?
Dear Datatables community,
I'm having a small problem with datatables.
We have some functions that alter the rendering for each row on a table.
And we're fetching records for roughly 300-500 rows.
When this is initially fetched, the rendering causes the DOM to be very slow (3-4 second delay where the page just freezes). Because it needs to render 300-500 rows with custom elements inside of them. I suspect the custom elements to be the cause of this slow rendering. But we need these elements either way.
To combat this slowness, we decided to go with the virtual scroller plugin, which initially only renders the amount of displaybuffer (which is set to 20), to the screen.
We also have a buttons plugin installed for datatables, which makes use of pdfhtml5 as a button.
This button's job is to create a pdf for all of the data in the table.
However, it seems that because we are using the scoller plugin, initially this button doesn't print all of the records, but just the first 20 that is set in the displaybuffer (since not all records are initially rendered in the table).
What are some workarounds that we could think of, to keep both the rendering of the rows fast for the entire table, as well as be able to print everything on first initialization using the pdfhtml5 button?
I have a few ideas for this:
Try to render the data in chunks somehow. (which still requires the user to wait before they can print everything)
Try to show a progress indicator that the table is rendering everything (which hopefully doesn't cause a freeze of the screen) and will still have the slow down but with a progress indicator and have everything loaded and fast after the initial data has been rendered, including the pdfhtml5 button. But we would really like to refrain from having a slow initial load.
Try to fix the slow rendering of the components that are inside of the datatable (preferable situation, but hard to figure out where it is causing such slowdowns... Could be due to our library that we use to render dom components.)
Conclusion
In other words, there is a bug where using both buttons plugin with pdfhtml5 doesn't work on initial render with the scroller plugin and displaybuffer set. (incompatible?)
As well as that there is a bug in our own code which causes slow rendering of rows in datatables. Which we try to circumvent with the scroller plugin.
Do any of you have a idea what we can try to otherwise fix this situation?
I currently don't have the time to create a example case, but I'll create one after this post soon.
Please help me figure this out.
Yours sincerely,
Hylke
Answers
Is Pagination allowed for your application? Enable it could save lot of time on initialization if you have many rows of data
I like @choc 's idea! But something else might also be relevant for you:
You could generate the pdf on the server and download it automatically when ready. On the server you could use tools like phpspreadsheet that you can also use to create pdfs. Then you have maximum flexibility and no performance issues.
I use that to create more complex reporting (Excel and pdf) and I also provide my users with a "download all documents" button that allows them to download all generated documentation for all of their contracts in one large zip file. So there are very many use cases for doing stuff like that on the server.