DataTables / TableTools

Please note that TableTools has now been retired and replaced by the Buttons and Select extensions which offers significant improvements and API integration with the rest of DataTables and the other extensions.
http://datatables.net/
Other
237 stars 149 forks source link

Bug exporting invisible column to PDF #19

Open ghost opened 11 years ago

ghost commented 11 years ago

I found a bug where a column with property "bVisible":false is not properly exported to PDF. I have written a sample HTML page, see https://gist.github.com/4599023. Unfortunately you have to run the HTML page from a local webserver because of Flash security restrictions. (It seams the .swf must be served from the same webserver as the HTML file, opening the file with the browser wan't work. I also wrote a jsFiddle with the same problem, perhaps because of the iframe).

The example contains a table with 4 columns, the 3rd column is hidden with "bVisible":false. I would like export all 4 columns, TableTools has been configured with:

"aButtons": [
    {
        "sExtends": "pdf",
        "mColumns": [0, 1, 2, 3],
        "sPdfOrientation": "landscape"
     }
]

The exported PDF has the 4th column merged into the 3rd.

rgavrilov commented 9 years ago

I'm getting the same behavior. Apparently bug is caused by fnCalcColRatios function, which calculates invisible column width as 0:

iWidth = aoCols[i].nTh.offsetWidth;

Not sure what the good fix would be though, to get proper width we need to render the column, i.e. make it visible.

DataTables commented 9 years ago

Hmmm - tricky one. Note sure what the correct thing to do is either. Possibly calculate the widths based on the content of the headers (strlen)... What I really would like is for the PDF generator to figure it out, but it doesn't seem to work that way.

afshinm commented 9 years ago

Any update on this?

DataTables commented 9 years ago

Sorry no. I've not had time to work on it yet.

EverpathDano commented 9 years ago

A hack, super easy, super fast, "at least it looks better than terrible" workaround until someone figures out something better:

iWidth = aoCols[i].nTh.offsetWidth;
if (!iWidth && typeof iDTTTDefaultHiddenColumnWidth !== 'undefined') {
    iWidth = iDTTTDefaultHiddenColumnWidth;
}

then we set the variable in the global scope to have a reasonable default (we have one table per page, we tune to that specific table). Even simpler could be iWidth = aoCols[i].nTh.offsetWidth || 200;.

I know, I know, it's hideous and horrible, I'm not suggesting this as a change to the mainline. It has the advantage of getting us up and running again without rolling our own PDF generator, I figured I'd pass it along to other desperate coders. :-)