Selecting/copying rows and using filters
Selecting/copying rows and using filters
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 example shows how to control the rows used for export:
https://datatables.net/extensions/buttons/examples/print/select.html
Kevin
Hi @kthorngren thanks for the link. I've managed to add control to selected rows so only certain columns are copied...
but I'm still unclear how to make this work with the copy button and selected rows hidden buy the filter. I can't find any mention of commands for this. Is it some kind of modifier?
http://live.datatables.net/vavejawo/2/
As noted in the link the
selector-modifier
describes all the options available. Sounds like you want{search: 'none'} and
{selected: true}` to get the selected rows regardless of the search applied. For example:http://live.datatables.net/yabozoyo/1/edit
Kevin
That's it Kevin! It works perfectly. I have been trying many different combinations without success. I was just experimenting with searching for the .selected class to export.