Failing to have both export buttons and also default column ordered

Failing to have both export buttons and also default column ordered

sronansronan Posts: 2Questions: 0Answers: 0

I am a beginner trying to both have export buttons and also a default ordering on the third column.

When, for example here: http://worldanimal.net/lp2.html
I have code for both order and buttons, I get the properly sorted 3rd column but no buttons visible

<script>
    $(document).ready(function () {
        $('#table1').DataTable( {
             "order": [[ 2, "desc" ]]
 dom: 'Blfrtip',
        buttons: [
            'csv', 'excel', { extend: 'pdf', orientation: 'landscape' }
        ]
    } );
    });
</script>

While when here: http://worldanimal.net/lp3.html
I remove this line: "order": [[ 2, "desc" ]]
the buttons work fine but the default ordering is gone.

<script>
    $(document).ready(function () {
        $('#table1').DataTable( {
 dom: 'Blfrtip',
        buttons: [
            'csv', 'excel', { extend: 'pdf', orientation: 'landscape' }
        ]
    } );
    });
</script>

Is there a way to have both the initial sorting on the third column, and also the export buttons?

Using the debugger, I get:
Summary information about the DataTables on this page.
Version check
Check to see if your page is running the latest DataTables software.
LibraryInfoInstalledLatest
DataTablesUp to date1.11.51.11.5
AutoFill-2.3.7
ButtonsUp to date2.2.22.2.2
ColReorder-1.5.5
Editor-2.0.7
FixedColumns-4.0.2
FixedHeader-3.2.2
KeyTable-2.6.4
Responsive-2.2.9
RowGroup-1.1.4
RowReorder-1.2.8
Scroller-2.0.5
SearchBuilder-1.3.2
SearchPanes-2.0.0
Select-1.3.4
Check for common issues
Run automated tests to check for common and previously reported issues.
15 tests complete. No failures or warnings found!

Thanks for any help,
S

Replies

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769

    Look at your browser's console. You are getting this error:

    Uncaught SyntaxError: Unexpected identifier

    You need to use commas to separate the Datatables options. For example:

            $('#table1').DataTable( {
                 "order": [[ 2, "desc" ]],  // Need a comma here
     dom: 'Blfrtip',
    

    Kevin

  • sronansronan Posts: 2Questions: 0Answers: 0

    Ah, terrific. That does indeed fix it. Thank you so much!!

Sign In or Register to comment.