vishwas jadav vishwas jadav - 21 days ago 7
PHP Question

How to display these data in data table with ajax?

{
"aaData": [
{
"id": "1",
"reg_d": "2017-09-15 10:15:57",
"fname": "Vishwas",
"lname": "Jadav",
"email": "vjadav@live.com"
},
{
"id": "50",
"reg_d": "2017-09-20 14:33:59",
"fname": "testA",
"lname": "testk",
"email": "test5@gmail.com"
},
{
"id": "51",
"reg_d": "2017-09-20 14:36:18",
"fname": "mvjh",
"lname": "kgjk",
"email": "teesth@jhk.com"
}
],
"draw": 5,
"recordsTotal": 35,
"recordsFiltered": 5
}


The Code I am using is:



<script type="text/javascript">
$(document).ready(function() {
$("#table1").dataTable({
"preocessing" : true,
"serverSide" : true,
"sAjaxSource" : "dtable2.php",
"columns" : [
{"data" : "aaData.1"},
{"data" : "aaData.3"},
{"data" : "aaData.4"},
{"data" : "aaData.5"},
{"data" : "aaData.2"},
]
});
});
</script>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">

</head>
<body>
<table id="table1">
<thead>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Date</th>
</tr>
</thead>
</table>
</body>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>

</html>





but I am getting A warning in result


"DataTables warning (table id = 'table1'): Requested unknown parameter
'0' from the data source for row 0"

Answer Source

You try this code:

<script type="text/javascript">
$(document).ready(function() {
$("#table1").dataTable({
  "preocessing" : true,
  "serverSide" : true,
  "sAjaxSource" : "dtable2.php",
  "columns" : [
    {"data" : "id"},
    {"data" : "fname"},
    {"data" : "lname"},
    {"data" : "email"},
    {"data" : "reg_d"},
  ]
});
});

See more: Columns render