multiple datatables with json data

multiple datatables with json data

bluebabe86bluebabe86 Posts: 3Questions: 0Answers: 0
edited September 2010 in General
Hi Allan ,
Is it possible to create 2 dataTables in the same page? I have 2 sets of json data , test1.json and test2.json. I want to create 2 dataTables from the 2 json sets. The code is something like this :

[code]
$.getJson(test1){
$('#dataTable1').datatable({
"aoColumns" : test1.columns;
"aaData" :test1.tabledata ;
});
}

$.getJson(test2){
$('#dataTable2').datatable({
"aoColumns" : test2.columns;
"aoColumns" :test2.tabledata ;
});
}
[/code]

This works if i want to display a single table, but throws exceptions for multiple tables. Am i doing something wrong ?

Thank you in advance :)
bluebabe86

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi bluebabe86,

    The syntax looks a little odd (the semi-colon in the object, and the use of datatable, rather than dataTable (capital T) - but the principle looks okay. If you use this does it work:

    [code]
    $.getJson(test1){
    $('#dataTable1').dataTable({
    "aoColumns" : test1.columns,
    "aaData" :test1.tabledata
    });
    }

    $.getJson(test2){
    $('#dataTable2').dataTable({
    "aoColumns" : test2.columns,
    "aoColumns" :test2.tabledata
    });
    }
    [/code]
    Allan
  • bluebabe86bluebabe86 Posts: 3Questions: 0Answers: 0
    Hi Allan,
    Thank you for your feedback. The semicolon and the function name was a typo. However, i realized the problem was that i was using the same table object (oTable) for both the tables. It works now. :-)
    Regards,
    bluebabe86
This discussion has been closed.