Help me please Build DataTable with JSON

Help me please Build DataTable with JSON

anthonny2890anthonny2890 Posts: 5Questions: 0Answers: 0
edited January 2014 in DataTables 1.9
Hello, I need help please. How to build a table from my data in Json format using DataTables?

I write this code, but it did not work:
[code]
var testdata = '[{"name":"Jhon","age":"23","sex":"M","phone":"210-828-5555"},{"name":"Barack","age":"30","sex":"M","phone":"210-828-4444"}]';

$('#example').dataTable(
{
"aaData": testdata,
"aoColumns": [{ "mDataProp": "name" },
{ "mDataProp": "age" },
{ "mDataProp": "sex" },
{ "mDataProp": "phone" }
]
}
);
[/code]
Thanks!

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    What does your HTML look like?
  • anthonny2890anthonny2890 Posts: 5Questions: 0Answers: 0
    edited January 2014
    I need to render the data in the table with the id = "example" does not work. I get this error: DataTables warning (table id = 'example'): Requested unknown parameter '1' from the data source for row 0. I do for make it work and show the table and its contents?

    [code]












    [/code]
  • anthonny2890anthonny2890 Posts: 5Questions: 0Answers: 0
    the solution was very simple aaData directly receives an array of objects, it is not necessary to turn in my string array of objects. solved and case closed.

    [code]
    $('#example').dataTable(
    {
    "aaData": [{"name":"Jhon","age":"23","sex":"M","phone":"210-828-5555"},{"name":"Barack","age":"30","sex":"M","phone":"210-828-4444"}],
    "aoColumns": [{ "mDataProp": "name" },
    { "mDataProp": "age" },
    { "mDataProp": "sex" },
    { "mDataProp": "phone" }
    ]
    }
    );
    [/code]

    Thanks!
This discussion has been closed.