Copying only column data

Copying only column data

pisislerpisisler Posts: 113Questions: 23Answers: 1
edited May 15 in DataTables 1.10

It is possible to select rows and copy them with copyHtml5? Copy button by default copies the row data even if only one cell or a column (or a group of columns) is selected. I couldn't extend the copy button to export column data by buttons.exportData()

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    This example shows how to export specified columns. Use the class .selected as the column selector. Is this what you are looking for?
    https://live.datatables.net/tofasane/1/edit

    Kevin

  • pisislerpisisler Posts: 113Questions: 23Answers: 1

    Ok good, but can't one copy button handle both? I mean we can change the selection mode with selectRows and selectColumns; but the copy doesn't respect this selection. If I set it to copy columns with this method, then copy will copy the columns but it will produce an error if the selection mode is rows.

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    edited May 16

    One option might be to create two buttons; one to export selected columns and the other to export selected rows. Then use the selectItems event to show/hide the appropriate buttons.

    Either use button().add() and button().remove() to toggle the displayed button. Or use button().node() along with jQuery or DOM methods to show/hide the buttons.

    but it will produce an error if the selection mode is rows.

    I don't see errors generated in this test case:
    https://live.datatables.net/tofasane/2/edit

    If there are no columns selected then nothing is copied regardless of the selection mode. You can select both columns and rows and the interesection of them will be copied.

    What error messages do you see? Maybe update the test case to show the issues you are having.

    Kevin

Sign In or Register to comment.