Excel export options: Selected modifier behaves different than documented

Excel export options: Selected modifier behaves different than documented

FeraudFeraud Posts: 20Questions: 6Answers: 0

Hi,

according to manual, you can choose if the Excel export included selected rows only or all rows:

"As of Buttons 1.5.0 the exported data from this method will automatically attempt to determine if any rows in the table are selected. If they are, the export will be restricted to this those rows. If no rows are selected, the full data set will be exported."_

Source: https://datatables.net/reference/api/buttons.exportData()

My Excel export options config looks like this:

                    modifier: {
                        order: 'current',
                        page: 'all',
                        selected: false,
                    },

The table is configured to allow selection of a single row:

            select: {
                style: 'single'
            },

When exporting to Excel, the selected row is NOT exported. When un-selecting the selected row, all rows are exported.

Looks like a bug to me. Questions:

  • Is this a bug?
  • If so, any idea for workaround? I tried to un-select the selected row before exporting, but did not find the right event where to intervene before the export occurs.

Thanks for your help!

Replies

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    selected: false means that only rows which are not selected will be exported. Valid values are false (export unselected rows), true (export selected rows) and null - default.

    There was a bug in this area, it would be worth trying the nightly versions of both Buttons and Select if it is still causing you issues.

    If even with the nightly's you are having problems, can you give me a link to a page showing the issue please?

    Allan

  • FeraudFeraud Posts: 20Questions: 6Answers: 0

    Hi Allan,

    thanks for your help.

    This is the observed behaviour of the selected parameter:

    • true: exports selected row only (as you told)
    • false: exports de-selected rows only (as you told)
    • null: exports no rows at all
    • seleted parameter not set = default: exports selected row only

    I tried using the nightly build for buttons and selected extensions using these references:

    <!-- Regular -->
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/cr-1.4.1/fc-3.2.4/sc-1.4.4/datatables.min.css"/>
    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.16/cr-1.4.1/fc-3.2.4/sc-1.4.4/datatables.min.js"></script>
    <!-- Nightly -->
    <link rel="stylesheet" type="text/css" href="https://nightly.datatables.net/buttons/css/buttons.dataTables.min.css"/>
    <script type="text/javascript" src="https://nightly.datatables.net/buttons/js/dataTables.buttons.min.js"></script>
    
    <script type="text/javascript" src="https://nightly.datatables.net/buttons/js/buttons.colVis.min.js"></script>
    <script type="text/javascript" src="https://nightly.datatables.net/buttons/js/buttons.print.min.js"></script>
    <script type="text/javascript" src="https://nightly.datatables.net/buttons/js/buttons.html5.min.js"></script>
    <script type="text/javascript" src="https://nightly.datatables.net/buttons/js/buttons.flash.min.js"></script>
    

    Unfortunately, the export button did not show up (print and columns visibility buttons worked fine).

    The table in question can be found here:

    https://dividendstocks.cash/growth-screener

    To use export, you need to register and I need to promote you to full member then.

    Regards,

    Torsten

  • allanallan Posts: 63,160Questions: 1Answers: 10,406 Site admin

    You need the Select nightly for it to work. I've put a little test case together here: http://live.datatables.net/korezaha/1/edit .

    Note that I've also include pdfmake and jszip to allow the Excel and PDF buttons to work.

    Allan

  • FeraudFeraud Posts: 20Questions: 6Answers: 0

    Sorry - I lost selected nightly in copy & paste process. Anyway, thanks for the sample. Let's got with this. When testing, I am not able to export all rows - regardless if selected or not.

    My expectation: Not setting the selected parameter means to ignore if the row is selected or not and just export all rows. Is this what you expect, too?

    Furthermore, setting the "selected: false" results in exported the selected rows only, like "selected: true" does. Doesn't feel right and looks like a second issue to me (see code sample below).

    Regards,

    Torsten

    ===

    I selected 2 rows. Expectation: these 2 rows are not exported, but the other rows are.
    Result: Only 2 selected rows are exported.

    $(document).ready(function() {
        $('#example').DataTable( {
          select: true,
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'copyHtml5',
                    exportOptions: {
                      rows: null,
                      selected: false,
                    }
                },
                {
                    extend: 'excelHtml5',
                    exportOptions: {
                      rows: null,
                      selected: false,
                    }
                },
                {
                    extend: 'pdfHtml5',
                    exportOptions: {
                      rows: null
                    }
                },
                'colvis'
            ]
        } );
    } );
    
This discussion has been closed.