Cannot reinitialise DataTable when adding new script

Cannot reinitialise DataTable when adding new script

MuiterMuiter Posts: 4Questions: 3Answers: 0

I am getting the message

DataTables warning: table id=dataTables-table_1 - Cannot reinitialise DataTable.

after adding this code:

<?php
<!-- Internationalisation responsive table -->
<script>
$('#dataTables-table_1').DataTable( {
language: {
    processing:     "Verwerken...",
    search:         "Zoeken:",
    lengthMenu:     "Bekijk _MENU_ records",
    info:           "_START_ tot _END_ van _TOTAL_ records zichtbaar",
    infoEmpty:      "0 van 0 records",
    infoFiltered:   "(totaal _MAX_ records)",
    infoPostFix:    "",
    loadingRecords: "Records worden geladen...",
    zeroRecords:    "Er zijn geen records gevonden",
    emptyTable:     "De tabel is leeg",
    paginate: {
        first:      "Eerste",
        previous:   "Vorige",
        next:       "Volgende",
        last:       "Laaste"
    },
    aria: {
        sortAscending:  ": sorteer oplopend",
        sortDescending: ": sorteer aflopend"
    }
}
} );
</script>
?>

I think it is because this is already in the script:

<?php
    <script>
    $(document).ready(function() {
        $('#dataTables-table_1').DataTable({
            responsive: true
        });
    });
    </script>
?>

But I am not succeeding in combing them, everything I try I am loosing the first or second JS script. Please help me out.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited May 2018 Answer ✓

    Yes the problem is they need to be combined. I suspect you are missing a comma separating the two options. Should look like this:

    $('#dataTables-table_1').DataTable( {
    responsive: true,   //notice the comma
    language: {
        processing:     "Verwerken...",
        search:         "Zoeken:",
        lengthMenu:     "Bekijk _MENU_ records",
        info:           "_START_ tot _END_ van _TOTAL_ records zichtbaar",
        infoEmpty:      "0 van 0 records",
        infoFiltered:   "(totaal _MAX_ records)",
        infoPostFix:    "",
        loadingRecords: "Records worden geladen...",
        zeroRecords:    "Er zijn geen records gevonden",
        emptyTable:     "De tabel is leeg",
        paginate: {
            first:      "Eerste",
            previous:   "Vorige",
            next:       "Volgende",
            last:       "Laaste"
        },
        aria: {
            sortAscending:  ": sorteer oplopend",
            sortDescending: ": sorteer aflopend"
        }
    }
    } );
    

    Kevin

  • MuiterMuiter Posts: 4Questions: 3Answers: 0

    Thx Kevin!

This discussion has been closed.