Read Data from JSON and Display in a Single Column
Read Data from JSON and Display in a Single Column
I am working on a data table that needs to fetch the data from a JSON file and display the data there in a single column under each other. So, instead of displaying rows under the headers, I want to display the column with regard to rows.
Basically, I want to display the numbers dynamically from a JSON file with AJAX request. is there a possible way to do that with Data tables ? or I should reshape my table to an ordinary table ?
here is the code:
Example | 11 | 1 |
---|---|---|
Example | 22 | 11 |
Example | 33 | 11 |
<script>
$(document).ready(function () {
$('#example').DataTable({
"ajax": 'data.json',
"columns": [
{ "data": "ex1" },
{ "data": "ex2" },
{ "data": "ex3" },
{ "data": "ex4" },
{ "data": "ex5" },
{ "data": "ex6" },
]
});
});
</script>
This question has an accepted answers - jump to answer
Answers
If the file is on the same local machine, you can just do something like this example here. If not, the server would need a script to read the file, which the
ajax
calls, in a similar fashion to this Editor example.Colin