Select rows and save data?

Select rows and save data?

sowasowa Posts: 12Questions: 2Answers: 0

I've been looking through all the extensions and what you can do but I might have missed this one. Can I use the select extension to highlight specific rows and save to an excel or pdf? (just those selected)

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    You can use the Buttons extension for this.

    Kevin

  • sowasowa Posts: 12Questions: 2Answers: 0

    I just want to save a selected few rows, not the entire table?

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    This example shows saving selected rows.

    Kevin

  • sowasowa Posts: 12Questions: 2Answers: 0

    how do I change it from print to say pdf? it's not working how I try it if it's possible

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    Please describe specifically what is not working with PDFs. Are you able to generate PDFs with all the data but not with selected rows?

    Please post your code so we can see what you are doing.

    Kevin

  • sowasowa Posts: 12Questions: 2Answers: 0

    Right now I have

      <script>
            $(document).ready(function() {
                $('#myTable').DataTable({
                    dom: 'Bfrtip',
                    select: true,
                    buttons: [
                    'copyHtml5', 'excel', 'pdf', 'csvHtml5'
                ]
            });
            });
        </script>
    

    It's just the basic buttons that downloads the entire table as the selected button. I'm interested to see if I can select specific rows, click PDF or excel and have only those show in my downloaded pdf or excel

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    Answer ✓

    You would use the same exportOptions as shown in the example I mentioned earlier for PDF, Excel, etc.

    https://datatables.net/extensions/buttons/examples/print/select.html

    Kevin

  • sowasowa Posts: 12Questions: 2Answers: 0

    I know but I can't get it to work. I'm trying to add it to the above code and I just get errors

  • sowasowa Posts: 12Questions: 2Answers: 0

    I tried it again today and it worked. thanks for the help

  • sowasowa Posts: 12Questions: 2Answers: 0

    Actually one other thing. This method seems to only allow one button type. When I try to have excel and pdf it only allows one.

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    What are the errors?

    Maybe you can post the code snippet of what you are trying to do. Or better create a test case showing the issue:
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • sowasowa Posts: 12Questions: 2Answers: 0

    I know this is wrong, it doesn't work. If I have just pdf it will work with pdf, or lke this it just shows excel. I've tried moving things around and trying different ways but I can't get multiple buttons. They don't all necessarily need to work with the selected, I'd like pdf and excel and maybe the other buttons could be more if needed. like copy, csv

    <script>
            $(document).ready(function() {
                $('#myTable').DataTable({
                    dom: 'Bfrtip',
                    buttons: [
                        {
                            extend: 'pdf',
                            extend: 'excel',
                            text: 'pdf',
                            text:'excel',
    
                        },
                        {
                            extend: 'excel',
                            text: 'selected excel',
                            extend: 'pdf',
                            text: 'selected',
                            exportOptions: {
                                modifier: {
                                    selected: true
                                }
                            }
                        }
                    ],
                    select: true
    
            });
            });
        </script>
    
  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    Answer ✓

    You need to group each button separately, like this:

    <script>
            $(document).ready(function() {
                $('#myTable').DataTable({
                    dom: 'Bfrtip',
                    buttons: [
                        {
                            extend: 'pdf',
                            text: 'pdf',
                            exportOptions: {
                                modifier: {
                                    selected: true
                                }
                            }
                        },
                        {
                            extend: 'excel',
                            text: 'selected excel',
                            exportOptions: {
                                modifier: {
                                    selected: true
                                }
                            }
                        }
                    ],
                    select: true
     
            });
            });
        </script>
    
  • sowasowa Posts: 12Questions: 2Answers: 0

    Thank you that works perfect

This discussion has been closed.