I really need your help here. I am new with jQuery DataTable. What I am doing is, I have a url (backend laravel php) that returns a JSON response like so:
[
{"kode_pt":1,"nama":"title","SK_path":"\/folder","email_PJ":"\/images","validasi":0},
{"kode_pt":2,"nama":"title","SK_path":"\/folder","email_PJ":"\/images","validasi":0}
]
What I am doing currently is using ajax jquery to GET the data, and add it to the table dynamically. Like this:
var content="";
$.ajax({
url: '{{route('get.pt')}}',
method: "GET",
dataType: "json",
success: function(data){
for(i=0; i<data.length; i++){
content+='<tr>'+
'<td>'+data[i].kode_pt+'</td>'+
'<td>'+data[i].nama+'</td>'+
'<td>'+data[i].validasi+'</td>'
+'<td><button id="accept" data-id='+data[i].kode_pt+' class="btn btn-success">Accept</button><button data-id='+data[i].kode_pt+' class="btn btn-danger">Decline</button><button id="view" data-id='+data[i].kode_pt+' class="btn btn-info">View</button></td>';
}
$("#verify-pt-body").html(content);
},
error: function(){
console.log("Ajax Error - getPT");
}
});
It works. But when I use the sort and search functionality of data table, the data shown onscreen disappears. After browsing, it turns out I cannot apply it to the table like that. I have to use the DataTable's functions to retrieve the json. I need help with that please. I have looked at few documentations but I have failed to get it working. Help would be much appreciated!!
Syntax of data tables I tried but failed:
$('#dataTable-verify-pt').DataTable({
responsive: true,
ajax:{
url: '{{route('get.pt')}}'
},
columns:[
{data: "kode_pt"},
{data: "nama"},
{data: "validasi"},
]
});
This is the format I'm trying to achieve with DataTable:

