Create multiple datatables with a JS function and parameters

Create multiple datatables with a JS function and parameters

MelodyNelsonMelodyNelson Posts: 213Questions: 33Answers: 2

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Hi,

I'm wondering if this kind of usage could work with DT (for now, I'm trying but success is not here)

<script>
function createTable10years(company, dataSet, tableID, chartID) {

    // do other things before

    var table10years = new DataTable(tableID, {
        data: dataSet,
        // all the settings and options for the table
    });
    
    return table10years;
};


$(document).ready(function() {
    
    var table10years_A = createTable10years('Company A', dataSet_10ansA, '#table10years_A', 'chart_10years_A'); 
    var table10years_B = createTable10years('Company B', dataSet_10ansB, '#table10years_B', 'chart_10years_B');
    var table10years_C = createTable10years('Company C', dataSet_10ansC, '#table10years_C', 'chart_10years_C');
    var table10years_D = createTable10years('Company D', dataSet_10ansD, '#table10years_D', 'chart_10years_D');

 });
</script>

Thanks

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,318Questions: 26Answers: 4,948
    Answer ✓

    Something like that should work just fine. What issues do you have? Are there errors in the browser's console?

    Here is a simple example based on your code:
    https://live.datatables.net/wexibije/1/edit

    Kevin

  • MelodyNelsonMelodyNelson Posts: 213Questions: 33Answers: 2

    Thanks.

    I don't have errors for now but the content of the tables are strange.
    My main suspect is the dataset, I need to watch it closely but I'll see tomorrow.
    I will let you know in a few days If I'm stuck.

    I just wanted to be sure to be on the good tracks to start changing my code again (it's for the page with multiples tables and charts you have already helped me before)

  • MelodyNelsonMelodyNelson Posts: 213Questions: 33Answers: 2

    @kthorngren
    My functions are working, I had problems with the dataset I could resolve. That was a good JS day :)
    Also, some JS errors when creating charts and « Highcharts GPT » helped me.
    My first time trying this kind of tool : https://www.highcharts.com/chat/gpt/

  • kthorngrenkthorngren Posts: 21,318Questions: 26Answers: 4,948

    Cool, glad its all working now!

    Kevin

Sign In or Register to comment.