TableTools PDF formatting issue w/ mColumns

TableTools PDF formatting issue w/ mColumns

manentiamanentia Posts: 14Questions: 0Answers: 0
edited July 2012 in General
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.

Replies

  • manentiamanentia Posts: 14Questions: 0Answers: 0
    I've narrowed down the issue.

    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.
  • manentiamanentia Posts: 14Questions: 0Answers: 0
    http://www.datatables.net/forums/discussion/7658/save-to-pdf-problem-with-bvisible-false-columns/p1

    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]
  • 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,535Questions: 1Answers: 10,475 Site admin
    @vinod_ccv - Please don't post the same question multiple times. There are already more questions than I can handle in the forum, and multiple questions just means less time to actually answer questions :-).

    If you don't want hidden columns in the output use mColumns - http://datatables.net/extras/tabletools/button_options#mColumns

    Allan
  • vinod_ccvvinod_ccv Posts: 75Questions: 0Answers: 0
    edited September 2012
    Thank you very much. It works . Customerized all the table tools buttons. Sorry ..I understand your time constrains and really appreciate your help .
This discussion has been closed.