Datatable wont load from Rest API, but works fine from SSP::complex json encode.
Datatable wont load from Rest API, but works fine from SSP::complex json encode.
drskunk
Posts: 1Questions: 1Answers: 0
I get no errors, just an empty table that says: No matching records found
Working response from adapted "ssp.class.php" script provided in the web:
{"draw":0,"recordsTotal":7,"recordsFiltered":7,"data":[{"id_cliente":"row_2","nombre":"jose","apellido":null,"domicilio":null,"localidad":"bs as","alta_fecha":null,"telefono":"1157446780","documento":null},... some other responses, }]}
Response from API rest (added some counts operations to match the SSP example:
{"draw":0,"recordsTotal":7,"recordsFiltered":7,"data":[{"id_cliente":"row_9","nombre":"JOSE","apellido":"ENRIQUE","domicilio":"LIBERTADOR
4000","localidad":"gonzalez catan","alta_fecha":"2020-11-13
10:29:11","telefono":"1157446780","documento":"180180"},... some other responses, }]}
JS for loading the table
$(document).ready(function() {
var table = $('#tablaClientes').DataTable( {
"language": {
"url":"assets/dist/json/Spanish.json"
},
"serverSide": true,
ajax: {
url: 'http://localhost/codoacodo_php/api/clientes/read.php' //<Not working, tried also api/clientes/read.php
},
// "ajax": "data/getClientes.php", <<Working fine, this is the SSP::complex test. Made with the test script in the page
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": '',
"render": function () {
return '<i class="fa fa-plus-square" aria-hidden="true"></i>';
}
},
{ "data": "id_cliente" },
{ "data": "nombre" },
{ "data": "apellido" },
{ "data": "documento" }
],
"order": [[1, 'asc']]
} );
ANY suggestion is greatly appreciated. Cheers!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This needs to match the
draw
parameter sent to the server. Its essentially a sequence number. The server side protocol is documented here:https://datatables.net/manual/server-side
Maybe you don't need server side processing. See this FAQ for some guidelines.
Kevin