My problem is that when loading the BD records in the datatable it takes several seconds, eh I saw that you can only show the data you need to see and from there make a request for the other data but I do not understand how does that my code is as follows:
Datatable:
var table = $('#tableProveedores').DataTable({
bDeferRender: true,
responsive: true,
columnDefs: [{
// "targets": 7,
"orderable": false
}],
scrollX: true,
data: response.provider,
columns: [
{data: "nombre"},
{
"render": function (data, type, row, meta){
var $select = $('<select class="form-control" id="tipo"><option id="basico" value="0">Basico</option><option value="1">Plata</option><option value="2">Oro</option><option value="3">Diamante</option></select>');
$select.find('option[value="'+row.tipo_cuenta+'"]').attr('selected', 'selected');
return $select[0].outerHTML;
}
},
{
"render": function (data, type, row, meta){
var $select = $('<select class="form-control" id="estado"><option value="0">Desactivado</option><option value="1">Pendiente</option><option value="2">Activo</option></select>');
$select.find('option[value="'+row.activo+'"]').attr('selected', 'selected');
return $select[0].outerHTML;
}
},
{data: "usuario"},
{data: "correo"},
{data: "contacto_celular"},
{"render":
function ( data, type, row ) {
return (row["localizacion_estado"] + ', ' + row["localizacion_pais"]);
}
},
{data: "fecha_creacion"},
],
language: {
"url": "//cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
}
});
Controller:
public function extraerProveedores() {
if($_POST) {
$data = $this->proveedor->getAllAdmin();
return $this->output->set_content_type("application/json")
->set_status_header(200)
->set_output(json_encode(['success' => true, 'provider' => $data]));
}
}
Model:
public function getAllAdmin()
{
$sql = 'SELECT proveedor.* ,usuario.correo, usuario.usuario, usuario.activo ,fecha_creacion FROM proveedor INNER JOIN usuario USING(id_usuario) ;';
$query = $this->db->query($sql);
return $query->result();
}
I searched already in the official documentation of Datatables but I can not understand how the data load can be optimized.