Can't get "grouped_array_index" working to print/PDF table with grouping

Can't get "grouped_array_index" working to print/PDF table with grouping

KanthKanth Posts: 20Questions: 9Answers: 0

Using https://datatables.net/forums/discussion/42916/row-grouping-with-printing: as a start, I'm trying to get Print and PDF to show as they do on screen. Based on the article, it seems that after I get the row grouping, I should be able to extend with "grouped_array_index", but I am unable to see any difference. What am I missing?

                var groupColumn = 0;

                $('#tblItemList').DataTable({
                    "columnDefs": [
                        { "visible": false, "targets": groupColumn }
                    ],
                    rowGroup: {
                        dataSrc: groupColumn
                    },
                    "lengthMenu": [[-1, 10, 25, 50], ["All", 10, 25, 50]],
                    dom: 'Bfrtip',
                    buttons: [
                        'copy', 'csv', 'excel', {
                            extend: 'pdfHtml5',
                            exportOptions: {
                                grouped_array_index: [groupColumn]
                            }
                        }, {
                            extend: 'print',
                            exportOptions: {
                                grouped_array_index: [groupColumn]
                            }
                        }               
                    ]
                });
            });

and the links are:

    <link rel="stylesheet" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css" />
    <link rel="stylesheet" href="//cdn.datatables.net/buttons/1.6.2/css/buttons.bootstrap4.min.css" />
    <link rel="stylesheet" href="//cdn.datatables.net/rowgroup/1.1.2/css/rowGroup.bootstrap4.min.css" />

    <script type="text/javascript" src="//code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="//cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript" src="//cdn.datatables.net/buttons/1.6.2/js/buttons.bootstrap4.min.js"></script>

    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>

    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>

    <script type="text/javascript" src="//cdn.datatables.net/buttons/1.6.2/js/buttons.html5.min.js"></script>
    <script type="text/javascript" src="//cdn.datatables.net/buttons/1.6.2/js/buttons.print.min.js"></script>

    <script type="text/javascript" src="//cdn.datatables.net/rowgroup/1.1.2/js/dataTables.rowGroup.min.js"></script>

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • KanthKanth Posts: 20Questions: 9Answers: 0

    Sure. I've re-built it for you using your data here:
    live.datatables.net/qoqotawa/1/edit?html,js,output
    Although, in this example, the PDF and Print buttons are not working at all, but they are on my page. I assume this may be a security feature?

  • kthorngrenkthorngren Posts: 21,376Questions: 26Answers: 4,957
    edited June 2020

    The PDF and Print buttons are working in your example but they aren't outputting the RowGroups. In the thread you linked there is more to the solution than just using grouped_array_index: [groupColumn]. The OP also customized the datatable-buttons.js to use this option. Did you make that change as well?

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Ah, I see, thanks for the test case. Yep, that's a complex one. There are a few examples that do work, such as here from this thread - hopefully that can get you going. There is an outstanding pull request open for this, but it's been pushed back due to other priorities - hopefully we can get to it soon,

    Colin

  • KanthKanth Posts: 20Questions: 9Answers: 0

    @colin Thank you. I thought that the change was incorporated into datatable-buttons.js already so I didn't make any changes. Also using cdn...
    Also, even in your example, the PDF button doesn't work. I don't see any errors, but I do get this warning, "Download is disallowed. The frame initiating or instantiating the download is sandboxed, but the flag ‘allow-downloads’ is not set. See https://www.chromestatus.com/feature/5706745674465280 for more details."

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Odd, it works for me here using Chrome and FF. What browser are you using?

    Colin

This discussion has been closed.