PDF Button - Error on filter all (zero records)
PDF Button - Error on filter all (zero records)
rodriformiga
Posts: 40Questions: 9Answers: 0
Hello @allan
The pdf
have a error on click and the datasource is empty.
In my case, I filtered the records on search field (wrote something to return zero records) and click in the button to export.
You can see this in the example: https://datatables.net/extensions/buttons/examples/initialisation/export.html
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
someone?
This seems to apply to all the "export" Buttons; they don't recognize that there is no data.
I suppose there may be circumstances in which someone might want to print an empty table, for example, to have a copy of the table structure. But is this intentional?
I'd say that was a bug - I'll get it raised and linked to this topic.
Cheers,
Colin
If you want to protect against exporting 0 records you can use something like
drawCallback
to check for the number of records usingpage.info()
to determine the number of records. Then usebutton().disable()
andbutton().enable()
as desired.Kevin
Thanks all! Fixed here and will be in the next release of Buttons which I think we should push out fair soon - its been a while!
Allan
Hmm... my comment is missing. Maybe I deleted it?
I had someone who didn't want the buttons enabled at all if there was no data in the view (even though it didn't error out due to the bug fix above). I enable/disable the export buttons with the code below.
Perfect - thanks for your reply. That looks like it could be a useful addition for others. Actually, I'm wondering if it should go into the core library...
Allan