Save to PDF - Problem with bVisible: false columns

Save to PDF - Problem with bVisible: false columns

varmajpvarmajp Posts: 3Questions: 0Answers: 0
edited December 2011 in TableTools
Tabletools function "fnCalcColRatios" not able to get the width of "bVisible: false" columns.
iWidth = aoCols[i].nTh.offsetWidth; - here width is 0 for "bVisible: false" columns
because of this pdf columns are overwritten/overlapped.
small hack solved my problem, but i want get the length from the table itself.
any solution ??

by assigning custom width we can avoid column overlapping.
if(iWidth == 0)
{
iWidth = 120;
}

Replies

  • manentiamanentia Posts: 14Questions: 0Answers: 0
    I've been struggling with the same issue and think I've come across a better hack. 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]
  • vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
    Hi,
    It works well . But what, if I don't want the invisible columns appear in the PDF or other out put forms.
    Any suggestion?
  • allanallan Posts: 63,089Questions: 1Answers: 10,388 Site admin
    See http://datatables.net/forums/discussion/10766/tabletools-pdf-formatting-issue-w-mcolumns#Item_3
This discussion has been closed.