Can't load JSON data into datatable

Can't load JSON data into datatable

celsomtrindadecelsomtrindade Posts: 4Questions: 2Answers: 1

Hey guys,
So, I've been trying to fill up my table with data from a json file, but i can't.
I already made a blank test with manual data, and the table is working fine. But when i try to load an external json file with the information i need, i can't load. The table just has a message "Loading..."

I already tried to google it and even tried to find a solution here, but, or i'm looking for the wrong thing or didn't found.. It's been more then 5hours looking for it =/

I'll post the code i'm using and hopefully someone can help me.

HTML:

<table class="" id="cfisico">
    <thead>
        <tr>
            <th>ID</th>
            <th>Nome</th>
            <th>CPF</th>
            <th>Nome Pai</th>
            <th>Nome Mãe</th>
            <th>Telefone</th>
            <th>Cidade</th>
            <th>Opções</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

Jquery:

$(document).ready(function() {
$('#cfisico').dataTable({
    "ajax": {
        "url": "data/c_fisico.json",
        "dataSrc": "tableData"
    }
});
});

JSON:

[   
    {
        "cd":0,
        "id":"C-0001",
        "nm_cliente":"Nome do Cliente",
        "cpf":"000.111.222-33",
        "nm_pai":"Nome COmpleto Pai",
        "nm_mae":"Nome Completo Mae",
        "tel":"48-9966-6699",
            "cidade":"Tubarão",
        "estado":"SC"
    },
    **rest of my json**
]

Can anyone help me?
Thanks.

This question has an accepted answers - jump to answer

Answers

  • AllanCochraneAllanCochrane Posts: 41Questions: 1Answers: 2
    Answer ✓

    You'll need to map the fields in the JSON to the columns in the table. Also you JSON needs to be in the correct format, look at http://jsfiddle.net/0rqxafhL/4/ for an example of the JSON format and how to define the columns. Hope that helps a bit

  • celsomtrindadecelsomtrindade Posts: 4Questions: 2Answers: 1

    Actually, after looking at your example, everything it was missing in my code was this "datatype:json;"

    After a lot of do/undo do/undo, i ended up removing that code and just noticed when i saw yours hahah thanks =D

This discussion has been closed.