Copy Button rearranging text
Copy Button rearranging text
When using the copy button where a cells string contains text with angle bracket characters ">Text HERE<" the data is between the angle brackets is copied to the front of the text. I assume this has to do with it thinking that it is HTML or something, but have tried adding options to disable html with no luck. Here is an example of the data displayed in the table and what gets copied to the clipboard.
Original: Boiler, Propane, Hot Water - >500 MBH and <=2500MBH
Copied: 500 MBH and Boiler, Propane, Hot Water - >500 MBH and <=2500MBH
This question has an accepted answers - jump to answer
Answers
I tried a test case with your example and it seems to copy the text just as it is. I have a cell with
Boiler, Propane, Hot Water - >500 MBH and <=2500MBH
and the pasted text isBoiler, Propane, Hot Water - >500 MBH and <=2500MBH
. Maybe you can update the example to replicate your issue:http://live.datatables.net/ripazemi/1/edit
Kevin
kthorngren thanks. Very strange here is a debug.
https://debug.datatables.net/asilew
OK looking at this further the issue is that I'm wrapping the column text in a span so that I can do hover display when the text gets truncated. Looks like the title attribute is messing things up. When I remove that all works as expected. Not sure if this is a bug or a setting I can set?
Here is updated code that replicates the issue:
http://live.datatables.net/bosaduga/1/edit
Good find. It does seem to be an issue with the copy process. Your
span
looks like this:<span title="Boiler, Propane, Hot Water - >500 MBH and <=2500MBH">Boiler, Propane, Hot Water - >500 MBH and <=2500MBH</span>
The copied data looks like this:
500 MBH and Boiler, Propane, Hot Water - >500 MBH and <=2500MBH
It appears the greater than in front of the 500 in the title is causing Datatables some issues resulting in the following text, up to the next less than, to be prepended to the expected text.
If you change that greater then to a less than (or something else) you will see the copied text is correct. Sounds like a bug that @allan or @colin will need to fix. You could work around the issue by using the
format.body
export option. Here is an example:http://live.datatables.net/lipomunu/1/edit
Kevin
Yes, this is caused by the regex that Buttons uses to strip HTML from data. Its unfortunately fairly lazy in that it won't correctly handle
>
characters inside attributes of HTML elements as you are seeing. The only proper way to do it is to parse it as HTML, but that is phenomenally slow when exporting data.At the moment the only workaround I can suggest for you is the one Kevin has kindly provided an example of. We could do that in Buttons core, and perhaps there should be an option for it - but again I'm concerned about performance.
Allan