<table id="datatable_lsg"...>
Rellenar todos los thead pero en el tbody solo poner:
<tbody>
</tbody>
Cuando generas el datatable ya especificar el ajax de donde se saquen los datos, los parámetros que les pasarás, así como las características de cada columna:
$('#datatable_lsg').dataTable( {
...
},
"processing": true,
"serverSide": true,
"ajax": {
"url": "{{ route('ajaxGetTodo') }}",
"data": {
"busq_by_texto": function() { return $('#busq_by_texto').val() },
}
},
'columns': [
{
data: 'idContent',
class: "",
createdCell: function (td, cellData, rowData, row, col) {
//Your js here.
$(td).css('text-align', 'center');
$(td).css('font-size', '1.2rem');
$(td).css('font-weight', 'bold');
}
},
{
data: 'title',
class: "",
createdCell: function (td, cellData, rowData, row, col) {
//Your js here.
$(td).css('text-align', 'center');
},
},
{
data: 'entradilla',
class: "",
createdCell: function (td, cellData, rowData, row, col) {
//Your js here.
$(td).css('text-align', 'center');
},
},
{
data: 'visibility',
class: "",
createdCell: function (td, cellData, rowData, row, col) {
//Your js here.
$(td).attr("hidden","");
},
},
],
createdRow: function (row, data, dataIndex) {
if (data["visibility"] == 0) {
}
else {
$('td', row).eq(3).html('visible');
$('#visibility_'+data["idContent"], row).attr('checked','checked');
}
}
});
En ajaxGetTodo:
...
foreach ($contents_list as $clave=>$valor) {
$data[] = array(
"idContent"=>$valor->idContent,
"visibility"=>$valor->visibility,
"title" => strip_tags($valor->content_title),
"entradilla" => strip_tags($valor->short_description),
);
}
$response = array(
"draw" => intval($draw),
"iTotalRecords" => $totalReg,
"iTotalDisplayRecords" => $totalRegFiltro,
"aaData" => $data,
);
echo json_encode($response);
No hay comentarios:
Publicar un comentario