Buttons exportOptions columns exporting all header columns

Buttons exportOptions columns exporting all header columns

puffsterpuffster Posts: 61Questions: 22Answers: 0

I have what I think is a very straightforward table - just three columns. I only want the second and third columns to be exported for excel, pdf, and printing. I'm using Buttons --> exportOptions --> columns and for some reason it's producing all three table header columns, but then only exporting columns one and two in the table body. As a result of their being three columns the data is spilling over into each row.

I tried to recreate the scenario here but for some reason I cannot get the Buttons to display so I don't know if it's being recreated or not...if somebody can tell me what I'm doing wrong in either case, I'd be most grateful :)

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    I fixed your test case. needed to add the buttons JS and CSS files.

    I ran through all 4 buttons and they export 2 column headers and 2 columns of data. The test case is not reproducing your issue but working correctly. Maybe there is something you are missing to cause the test case to recreate the problem.

    Updates here:
    http://live.datatables.net/tucikewi/2/edit

    Kevin

  • puffsterpuffster Posts: 61Questions: 22Answers: 0

    shoot, thanks Kevin....I thought I had included the nightly Buttons, maybe I overlooked something. Also, I've been thinking about it and I totally forgot that I modified the datatables.js file a couple days ago to allow for tables with multiple header rows to export all the header rows. I used the modifications that this poster provided:

    How to add second footer to pri...

    The code reroutes to this function below to grab the multiple header rows, so I'm hoping the issue is in here somewhere. I'm getting ready to dig in and I'm sorry about wasting anybody's time by not remembering I did this :neutral:

    var getHeaders = function( dt ){
        var thRows = dt.nTHead.rows;
        var numRows = thRows.length;
        var matrix = [];
     
        // Iterate over each row of the header and add information to matrix.
        for ( var rowIdx = 0;  rowIdx < numRows;  rowIdx++ ) {
            var $row = $(thRows[rowIdx]);
     
            // Iterate over actual columns specified in this row.
            var $ths = $row.children("th");
            for ( var colIdx = 0;  colIdx < $ths.length;  colIdx++ )
            {
                var $th = $($ths.get(colIdx));
                var colspan = $th.attr("colspan") || 1;
                var rowspan = $th.attr("rowspan") || 1;
                var colCount = 0;
              
                // ----- add this cell's title to the matrix
                if (matrix[rowIdx] === undefined) {
                    matrix[rowIdx] = [];  // create array for this row
                }
                // find 1st empty cell
                for ( var j = 0;  j < (matrix[rowIdx]).length;  j++, colCount++ ) {
                    if ( matrix[rowIdx][j] === "PLACEHOLDER" ) {
                        break;
                    }
                }
                var myColCount = colCount;
                matrix[rowIdx][colCount++] = $th.text();
            
                // ----- If title cell has colspan, add empty titles for extra cell width.
                for ( var j = 1;  j < colspan;  j++ ) {
                    matrix[rowIdx][colCount++] = "";
                }
              
                // ----- If title cell has rowspan, add empty titles for extra cell height.
                for ( var i = 1;  i < rowspan;  i++ ) {
                    var thisRow = rowIdx+i;
                    if ( matrix[thisRow] === undefined ) {
                        matrix[thisRow] = [];
                    }
                    // First add placeholder text for any previous columns.                
                    for ( var j = (matrix[thisRow]).length;  j < myColCount;  j++ ) {
                        matrix[thisRow][j] = "PLACEHOLDER";
                    }
                    for ( var j = 0;  j < colspan;  j++ ) {  // and empty for my columns
                        matrix[thisRow][myColCount+j] = "";
                    }
                }
            }
        }
    
        return matrix;
    };
    
  • puffsterpuffster Posts: 61Questions: 22Answers: 0

    Just wanted to give an update that the issue was in the new code to account for multiple headers. I was able to add a couple of lines of code to the solution and it works like a charm. The updated code can be found in the original post:

    https://datatables.net/forums/discussion/comment/106434/#Comment_106434

This discussion has been closed.