i'm trying to populate my table (DataTables.net) using ajax. The received values are from an json object generated by my php script. For the moment i can manage it by using classic method, vars from php but i want to switch to json method now.
Here is my jsfiddle where i have tested many things without any success :\
$(document).ready(function() {
$('#example').DataTable({
"bProcessing": true,
"ajax": {
"url": "http://www.json-generator.com/api/json/get/bUCyQgmGeW?indent=2",
"dataSrc": "syncok"
},
"columns": [
{ "data": "Ticket_RT" },
{ "data": "Last_up_time" },
{ "data": "Last_down_time" },
{ "data": "Date_du_Diag" },
{ "data": "Commentaire_FT" },
{ "data": "Code_Retour_FT" },
{ "data": "Supprimer" }
]
});
});
body {
font-family: "Open Sans", "Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif;
}
<script src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<div id="exampleDiv">hello</div>
<table width="100%" class="display" id="example">
<thead>
<tr>
<th>Ticket RT</th>
<th>Last up time</th>
<th>Date du Diag RT</th>
<th>Commentaire FT</th>
<th>Code Retour FT</th>
<th>Supprimer</th>
</tr>
</thead>
</table>
I hope someone can help me with this problem, i have tried many snippet from stackoverflow and from the original documentation but i can't manage it by myself !
Thank you in advance for your help :)
Regards.
EDIT :
To fix this issue you must add this before .DataTable function :
$("#example").empty();
And add an option "bDestroy": true, to .DataTable function.
Solution from this thread : DataTables Forum
EDIT 2 :
Excuse me i'm blind ! Now my title disappear after adding .empty() function... Now i'm trying to fix this another problem, so if someone can put me in the right way ! Thank you in advance for the help :)
FIX :
$(document).ready(function() {
$("#ret_syncok").empty();
$('#ret_syncok').DataTable( {
"bDestroy": true,
"bProcessing": true,
"ajax": {
"url": "js/optionsTables/cMass_ret_syncok.php",
"dataSrc": "syncok"
},
"columns": [
{ "data": "Ticket_RT" },
{ "data": "Last_up_time" },
{ "data": "Last_down_time" },
{ "data": "Date_du_Diag_RT" },
{ "data": "Commentaire_FT" },
{ "data": "Code_Retour_FT" },
{ "data": "Supprimer" }
],
"columnDefs": [
{ "title": "Ticket RT", "targets": 0 },
{ "title": "Last up time", "targets": 1 },
{ "title": "Last down time", "targets": 2 },
{ "title": "Date du Diag_RT", "targets": 3 },
{ "title": "Commentaire FT", "targets": 4 },
{ "title": "Code Retour FT", "targets": 5 },
{ "title": "Supprimer", "targets": 6 }
]
});
});
I hope that can help someone else :)