Multiple header rows are not exported

Multiple header rows are not exported

steve_manningsteve_manning Posts: 2Questions: 0Answers: 0
edited March 2011 in TableTools
In the following example table is there a way to export all of the header rows when using Copy, PDF etc. rather than just the second row?

[code]



Common Col
Col Grp 1
Col Grp 2
Col Grp 3


Col 1
Col 2
Col 3
Col 1
Col 2
Col 3
Col 1
Col 2
Col 3




11.1.11.1.21.1.31.2.11.2.21.2.31.3.11.3.21.3.3


22.1.12.1.22.1.32.2.12.2.22.2.32.3.12.3.22.3.3


33.1.13.1.23.1.33.2.13.2.23.2.33.3.13.3.23.3.3


44.1.14.1.24.1.34.2.14.2.24.2.34.3.14.3.24.3.3


55.1.15.1.25.1.35.2.15.2.25.2.35.3.15.3.25.3.3



[/code]

Looking in the source, it looks as if the Copy and other functions use the aoColumns array of the DataTable as their data source so I suspect the answer is no as the array does not contain the other header values.

TIA

Steve

Replies

  • VacciphVacciph Posts: 9Questions: 1Answers: 0
    I'm having the same problem Steve, were you able to find a solution for this problem?

    thanks,
    V
  • steve_manningsteve_manning Posts: 2Questions: 0Answers: 0
    We ended up rolling our own solution to extract the header info out of DOM as a sort of a cludge:

    [code]
    /* =============================================================================

    Get all of the header rows and return as a delimited string

    ============================================================================= */
    function fnGetAllHeaders(oConfig) {
    if (oConfig.sDataTableId == "NOTSET") {
    alert("WARNING: The sDataTableId parameter must be set to the data tables id in order to generate the full header set.")
    return "";
    };

    // Get the correct line ending
    if ( oConfig.sNewLine == "auto" ) {
    var sNL = navigator.userAgent.match(/Windows/) ? "\r\n" : "\n";
    } else {
    var sNL = oConfig.sNewLine;
    }

    var sOutput = "";

    // Get the report title and add it
    if (oConfig.sSubTitle != "") {
    sOutput+=oConfig.sSubTitle.replace( /<.*?>/g, "" ).replace(/
    /g,sNL)+sNL+sNL;
    };

    // Get the header cells
    var sElementName = "#"+oConfig.sDataTableId+"_wrapper .dataTables_scrollHeadInner thead tr"
    $(sElementName).each(function(index) {
    $(this).children("th").each(function(index) {
    if ($(this).attr("rowspan")!= 1) {
    alert("WARNING: Rowspan Found in Header. This will corrupt the header data")
    };

    var iCs=$(this).attr("colspan");
    for(var i=1;i <= iCs; i++) {
    var sFld=trim($(this).text().replace(/\n/g," ").replace( /<.*?>/g, "" ));
    sOutput+=oConfig.sFieldBoundary + sFld + oConfig.sFieldBoundary + oConfig.sFieldSeperator;
    };
    });
    sOutput+=sNL;
    });

    // Return the text
    return sOutput;
    };
    [/code]

    and...

    [code]
    /* =============================================================================

    Get all of the header rows and return as formatted html (table rows)

    ============================================================================= */
    function fnGetPrtHeaders(sTableId) {
    var sOutput = "";

    // Get the header cells
    var sElementName = "#"+sTableId+"_wrapper .dataTables_scrollHeadInner thead tr"
    $(sElementName).each(function(index) {
    sOutput+="";
    $(this).children("th").each(function(index) {
    var iCS=$(this).attr("colspan");
    var iCW=Math.round($(this).width());
    var sFld=trim($(this).text().replace(/\n/g," ").replace( /<.*?>/g, "" ));
    sOutput+="" + sFld + "";
    });
    sOutput+="\n";
    });

    // Return the text
    return sOutput;
    };

    [/code]

    - Steve
This discussion has been closed.