Copying (or printing) selected rows doesn't export any rows

Copying (or printing) selected rows doesn't export any rows

AGladwinAGladwin Posts: 4Questions: 1Answers: 1

When using exportOptions: {modifier: {selected: true} } with the copy button and select:true, no rows are actually copied, only the headers are copied. I checked the example and it doesn't work either - this was reported by another user (https://www.datatables.net/forums/discussion/29937/print-selected-demo-not-working#latest) - and it is marked as answered - but the example still doesn't work and nor does my own code. Please advise.

This question has accepted answers - jump to:

Answers

  • AGladwinAGladwin Posts: 4Questions: 1Answers: 1

    Has a fix been found for this yet please?

  • modulusOperatormodulusOperator Posts: 7Questions: 0Answers: 1

    +1

  • modulusOperatormodulusOperator Posts: 7Questions: 0Answers: 1
    Answer ✓

    I found where the problem is occurring (or at least a symptom of the problem that is causing this issue) and made a fix, but.... WARNING: there could be unintended consequences of my fix, use at your own risk. My fix seems to work in my use case, when selecting rows to then export using the Buttons extension. For my use case the following has allowed me to export selected rows:
    In the Select extension at line ~580 I changed:

    if ( (selected === true && data._select_selected === true) ||
         (selected === false && ! data._select_selected ) ) 
    {
        out.push( indexes[i] );
    }
    

    to:

    if (o.type === "row") {
        if ( (selected === true && data._select_selected === true) ||
             (selected === false && ! data._select_selected ) ) 
        {
            out.push( indexes[i] );
        }
    } else if (o.type === "column") {
        out.push( indexes[i] );
    }
    

    Again, this may not be the best fix, may only be putting a band-aid on an underlying problem, and could have unintended consequences. Use at your own risk.

  • AGladwinAGladwin Posts: 4Questions: 1Answers: 1

    Thanks for the suggestion - and I will heed the warning.

  • allanallan Posts: 63,747Questions: 1Answers: 10,509 Site admin
    Answer ✓

    Hi,

    This issue was fixed by this commit is Buttons. It will be included in the 1.0.4 release and is in the nightly version if you want to use it there.

    Regards,
    Allan

This discussion has been closed.