Copying only column data
Copying only column data
pisisler
Posts: 113Questions: 23Answers: 1
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
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
Ok good, but can't one
copy
button handle both? I mean we can change the selection mode withselectRows
andselectColumns
; but thecopy
doesn't respect this selection. If I set it to copy columns with this method, thencopy
will copy the columns but it will produce an error if the selection mode is rows.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()
andbutton().remove()
to toggle the displayed button. Or usebutton().node()
along with jQuery or DOM methods to show/hide the buttons.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