Buttons don't appear and I got string error

Buttons don't appear and I got string error

eilonash92eilonash92 Posts: 5Questions: 2Answers: 0

Whenever I add the buttons all the datatables don't work and I have a string error...

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jq-3.2.1/dt-1.10.16/b-1.5.1/b-html5-1.5.1/datatables.min.css"/>

<

script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"</script>

<

script src="//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"</script>

$(document).ready( function () {
var table = $('#ServerTable').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'excel', 'pdf'
]

            "paging":   false,



    "columnDefs": [
                { targets: [0, 9], "orderable": false},
                {
                    type: 'natural',
        "searchable": true,
        "orderable": true,
        "targets": 1



    } ],
    "order": [[ 1, 'asc' ]]
} );

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    I see a couple issues. First is your CSS and JS.

    This:
    script src="//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"</script>

    Duplicates the CSS loaded in this line:
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jq-3.2.1/dt-1.10.16/b-1.5.1/b-html5-1.5.1/datatables.min.css"/>

    The buttons CSS is loaded with this portion b-1.5.1/b-html5-1.5.1. But it doesn't look like you are loading the buttons JS files as you only have this:
    script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"</script>

    I would recommend using the Download Builder to build the proper CSS and JS. You also need to include JSZip for Excel and pdfmake for PDF. Replace what you have above with the newly generated CSS and JS.

    Second you have a syntax error (which is probably the string error) in your Datatables init code. You need to change this:

    buttons: [
    'copy', 'excel', 'pdf'
    ]
    

    To include a comma to separate the parameters, to look like this:

    buttons: [
    'copy', 'excel', 'pdf'
    ],
    

    Kevin

  • eilonash92eilonash92 Posts: 5Questions: 2Answers: 0

    Now the buttons appear!
    But when I click on one of them they seem to be loading... but not functioning .. it seem like it take them long time to continue

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    But when I click on one of them they seem to be loading... but not functioning

    I would suspect a Javascript error. Have you looked at your browser's console for messages?

    Kevin

This discussion has been closed.