Selecting/copying rows and using filters

Selecting/copying rows and using filters

silkspinsilkspin Posts: 141Questions: 32Answers: 5

I’m using a “copyHtml5” button and select: {style: 'multi’}, to select rows. In my local dev version I initially disable the copy button otherwise it automatically allows the copying of all rows if none are selected. I only allow it to become active if if($("#datatable > tbody > tr.selected").length > 0). All works OK and even when the current page doesn’t have anything selected it still successfully copies the selected rows on other pages.

However, I’ve just encountered a problem when I select rows and then use a filter. Previously selected rows that are now hidden are ignored from the copy yet the footer still shows "x rows selected". The behaviour now is if the page shows 10 values (none of which are the selected rows) it actually copies all 10 of those unselected rows.

Is there a way around this problem that can stop the copy button defaulting to copying the filtered results if selected rows are hidden? I’d also like to stop the entire table being copied if no rows are selected?

I’ve added a test case to show the issue and some steps to demonstrate below… http://live.datatables.net/vavejawo/1/

STEPS TO REPRODUCE
* Select "Angelica Ramos" & "Bradley Greer" who are both in the London office. This shows "2 rows selected" in the footer.
* In the office filter select "Edinburgh". This still shows "2 rows selected" in the footer.
* Click the "Copy" button. This shows all 19 Edinburgh rows have been copied.
* Now if just one of the "Edinburgh" rows is selected it shows "3 rows selected" in the footer.
* Clicking the "Copy" button shows just the one Edinburgh rows has been copied.
* Remove the "Office" column filter and click "Copy" and it shows 3 rows have been copied.

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.