Print and exportOptions.columns - BUG

Print and exportOptions.columns - BUG

rodriformigarodriformiga Posts: 38Questions: 8Answers: 0

Hello @allan

In the print, with the exportOptions.columns set, I have wrong class set in the result columns.
Ex: I put 5 columns, the first with class = select-checkbox, the second aligned to the right, the third centered and the other unformatted
But in ExportOption, I will only print columns 2 and 5

As a result I will have column 2 with class select-checkbox (as it refers to vector 0 of the columns) and column 5 right-aligned (because the vector points to the second column)

In short, the data is different from the columnClasses

The wrong line is this: https://github.com/DataTables/Buttons/blob/8925bf655f1ee4128f63ca1a77bb2077228d750c/js/buttons.print.js#L106

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,721Questions: 1Answers: 10,108 Site admin

    Can you give me a link to a page showing the issue please?

    If you want to export all but the first column use columns: ':gt(1)'.

    Allan

  • rodriformigarodriformiga Posts: 38Questions: 8Answers: 0

    Hello @allan

    Here is the sample: https://jsfiddle.net/rodriformiga/u78genkx/6/

    See, the first column in the print page have the class "select-checkbox" but the correct column is excluded from the print view. The same about the column "Data", right-aligned in the datatable, but in the print the column right-aligned is "Valor"

  • allanallan Posts: 61,721Questions: 1Answers: 10,108 Site admin

    Got it! Thanks for the test case. I've committed the fix here and you can see it with your example here.

    Regards,
    Allan

  • rodriformigarodriformiga Posts: 38Questions: 8Answers: 0

    Hey, @allan

    Sorry, but I think you forgot something. The indexes of the column:

            var columnClasses = dt.columns( config.exportOptions.columns ).indexes().map( function (col, key) {
                return dt.settings()[0].aoColumns[col].sClass;
            } );
    
  • allanallan Posts: 61,721Questions: 1Answers: 10,108 Site admin

    Doh! Thanks for pointing that out - I only checked for it stripping classes, which it of course did there. Proper fix here. Updated example.

    Allan

  • rodriformigarodriformiga Posts: 38Questions: 8Answers: 0
    edited June 2018

    No problems @allan

    And... Sorry again... I think this solution will not work either...

    In my last comment I put the code that worked for me.
    I put a console.log after this code to see the correct classes of each column, and the column "Data" needs to be right-aligned in the print page to work correctly.

    In your last code, the columnClasses is an array of 1's

  • allanallan Posts: 61,721Questions: 1Answers: 10,108 Site admin
    Answer ✓

    This time I've really got it!

    What a mess - sorry!

    Allan

  • rodriformigarodriformiga Posts: 38Questions: 8Answers: 0

    Yeahh @allan

    Thanks... Now, all it's Ok!

    Rodrigo

This discussion has been closed.