How to Load Data from JSON in DataTables?

How to Load Data from JSON in DataTables?

marcellosalasmarcellosalas Posts: 1Questions: 1Answers: 0

Hey everyone,

I’m new to DataTables and trying to load data from a JSON file, but I’m struggling a bit. I have a basic table set up, and I want it to fetch and display data from an external JSON file. Here’s what I’ve tried so far:

$(document).ready(function() {
    $('#example').DataTable({
        "ajax": "data.json",
        "columns": [
            { "data": "name" },
            { "data": "position" },
            { "data": "office" }
        ]
    });
});

The table appears, but no data is showing. I checked the browser console, and there are no errors. My data.json file is correctly formatted. What could be the issue? Do I need to configure anything on the server side? I have also gone through this thread https://datatables.net/forums/discussion/56116/loading-datatables-from-a-json-file-sac-analytics-cloud but still looking for some more help.

Any help would be appreciated!

Thanks in advance.

With Regards,
Marcelo Salas

Answers

  • allanallan Posts: 64,015Questions: 1Answers: 10,555 Site admin

    Hi Marcelo,

    That looks like all you should need. See this example for a working demo.

    If it isn't working for you, please link to your page so I can take a look and help to debug it.

    Allan

Sign In or Register to comment.