Loading JSON data into a table
Loading JSON data into a table
firepro20
Posts: 1Questions: 1Answers: 0
Hi I want to load JSON data to be display in a table with id studTable as shown below
<table id="studTable" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
<caption>Students</caption>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Surname</th>
<th>DOB</th>
</tr>
</thead>
</table>
This is the JSON code
$(document).ready(function() {
alert("Hello");
var s1 = [{
"ID":"1",
"Name":"Peter",
"Surname":"Smith",
"DOB":"1/1/1990",
//"Payment_Methods":{
// "ID":"1",
// "Type":"Credit Card",
// "Amount":"150.00"
}
}]
$('#studTable').dataTable( {
data: s1,
columns: [
{ title: "ID" },
{ title: "Name" },
{ title: "Surname" },
{ title: "DOB" }
]
} );
} );
This discussion has been closed.
Answers
Use
columns.data
notcolumns.title
to tell DataTables where to get the data for each column.Allan