TableTools PDF formatting issue w/ mColumns
TableTools PDF formatting issue w/ mColumns
I've noticed a formatting issue using the PDF feature of TableTools.
Without setting mColumns the output is fine, but when setting mColumns to an array of columns, the width's are off and there ends up being an overlap of several columns on the far right.
Without setting mColumns the output is fine, but when setting mColumns to an array of columns, the width's are off and there ends up being an overlap of several columns on the far right.
This discussion has been closed.
Replies
If a column is specified in mColumns that's hidden in the main table (using the ColVis plugin), that column appears to get a 0 width in the PDF export.
I found another post regarding this issue, which helped point me toward a work-around. I don't know if this is the best/correct way to approach this issue, but it's been working for me:
Modify the "fnCalcColRatios" function of TableTools.js script from:
[code]
"fnCalcColRatios": function (oConfig) {
var
aoCols = this.s.dt.aoColumns,
aColumnsInc = this._fnColumnTargets(oConfig.mColumns),
aColWidths = [],
iWidth = 0,
iTotal = 0,
i, iLen;
for (i = 0, iLen = aColumnsInc.length; i < iLen; i++) {
if (aColumnsInc[i]) {
iWidth = aoCols[i].nTh.offsetWidth;
iTotal += iWidth;
aColWidths.push(iWidth);
}
}
for (i = 0, iLen = aColWidths.length; i < iLen; i++) {
aColWidths[i] = aColWidths[i] / iTotal;
}
return aColWidths.join('\t');
}
[/code]
to:
[code]
"fnCalcColRatios": function (oConfig) {
var
aoCols = this.s.dt.aoColumns,
aColumnsInc = this._fnColumnTargets(oConfig.mColumns),
aColWidths = [],
iWidth = 0,
iTotal = 0,
i, iLen;
for (i = 0, iLen = aColumnsInc.length; i < iLen; i++) {
if (aColumnsInc[i]) {
iWidth = aoCols[i].nTh.offsetWidth;
/*-------- BEGIN NEW CODE ---------------------------------*/
if (iWidth == 0) {
var oTable = this.s.dt.oInstance;
oTable.fnSetColumnVis(i, true);
iWidth = aoCols[i].nTh.offsetWidth;
oTable.fnSetColumnVis(i, false);
}
/*-------- END NEW CODE -----------------------------------*/
iTotal += iWidth;
aColWidths.push(iWidth);
}
}
for (i = 0, iLen = aColWidths.length; i < iLen; i++) {
aColWidths[i] = aColWidths[i] / iTotal;
}
return aColWidths.join('\t');
}
[/code]
It works well . But what, if I don't want the invisible columns appear in the PDF or other out put forms.
Any suggestion?
If you don't want hidden columns in the output use mColumns - http://datatables.net/extras/tabletools/button_options#mColumns
Allan