cannot reinitialize datatable error also with retrieve option true

cannot reinitialize datatable error also with retrieve option true

bernhardbbernhardb Posts: 5Questions: 2Answers: 0

hello!

i'm creating a module for processwire and everything is working really well. i have one big problem though:

i'm initializing my table via the module, taking care of adding buttons, filter options and the like

// DataTablesGlobal.js
$(document).ready(function() {
        $table = $('#todo-details');

        // some options here like preparing "defs" array
        // all other options come from HTML data attributes

        $table.DataTable({ columnDefs: defs });
}

then i want to be able to do some kind of stuff with this initialized table from another javascript file

// todo-details.js
$(document).ready(function() {
    $table = $('#todo-details');
    datatable = $table.DataTable({retrieve: true});
}

this throws an error pointing me to this site: datatables.net/tn/3

but that does not help me... any help? how can i get my datatable instance without the error?

thank you!

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    but that does not help me...

    The "Diagnosis" section at datatables.net/tn/3 seems pretty clear to me. It even shows a code example quite similar to your own code,

  • allanallan Posts: 63,822Questions: 1Answers: 10,517 Site admin
    Answer ✓

    Your code looks like it should work to me. We'd need need a link to a page showing the issue to be able to help diagnose why it isn't working. Probably execution order.

    Allan

  • bernhardbbernhardb Posts: 5Questions: 2Answers: 0

    wow, thank you allan for your quick response and all your work you put into this great piece of software!! it's really making my project for a client worlds better than i ever thought.

    i solved the problem when trying to setup a test installation for you, so your answer that it "should" work helped me :smile:

    the reason for the message was that i did not control the ORDER of the script tags, meaning i had something like this:

    <head>
    <script src="todo-details.js"></script>
    <script src="DataTablesGlobal.js"></script>
    </head>
    

    so this led to this calls:

    $table.DataTable(); // from global.js
    $table.DataTable( ## my options ## ); // from todo-details.js
    

    then the error message totally makes sense. maybe you can add a hint to the error docs page that one should take care of loading order if the code is split up in several files

    thanks again and all the best! :smile:

  • allanallan Posts: 63,822Questions: 1Answers: 10,517 Site admin

    That would do it. Nice one spotting that and thanks for letting me know that it is resolved.

    Allan

This discussion has been closed.