I have an array that contains two sub-arrays, one called "version_anio"and another called "sedes",I pass the main array to Datatable and it only can display two values "escuela" and "curso" , since they are on the main array, how could I display both nested arrays on Yajra Datatable.I tried looping inside the columns with no success!
<!-- language: php -->
<table class="table table-bordered data-table" id="tabla-resumen">
<thead>
<tr>
<th>Escuelas</th>
<th>Curso</th>
@foreach($data[0]->version_anio as $v_anio) <---table headers load dynamic
<th> {{ @$v_anio->name }} </th>
@endforeach
{{-- @foreach($data[0]->sedes as $sede)
<th> {{ @$sede->label }} </th>
@endforeach --}} --
{{-- <th>Total Inscritos</th> --}}
</tr>
</thead>
<tbody>
</tbody>
</table>
//DATATABLE
var table = $('#tabla-resumen').DataTable({
processing: false,
serverSide: false,
ajax: '{{ route("admin/resumen_anual") }}',
dom: 'Bfltip',
columns: [
{data: 'escuela', name: 'escuela'},
{data: 'curso', name: 'curso'},
// $.each(version_anio, function(index, value) { <---- looping failed
// {data:'version_anio', name:'version_anio'},
// )},
],language: {
url: '//cdn.datatables/plug-ins/2.1.4/i18n/es-MX.json',
},
});
I have an array that contains two sub-arrays, one called "version_anio"and another called "sedes",I pass the main array to Datatable and it only can display two values "escuela" and "curso" , since they are on the main array, how could I display both nested arrays on Yajra Datatable.I tried looping inside the columns with no success!
<!-- language: php -->
<table class="table table-bordered data-table" id="tabla-resumen">
<thead>
<tr>
<th>Escuelas</th>
<th>Curso</th>
@foreach($data[0]->version_anio as $v_anio) <---table headers load dynamic
<th> {{ @$v_anio->name }} </th>
@endforeach
{{-- @foreach($data[0]->sedes as $sede)
<th> {{ @$sede->label }} </th>
@endforeach --}} --
{{-- <th>Total Inscritos</th> --}}
</tr>
</thead>
<tbody>
</tbody>
</table>
//DATATABLE
var table = $('#tabla-resumen').DataTable({
processing: false,
serverSide: false,
ajax: '{{ route("admin/resumen_anual") }}',
dom: 'Bfltip',
columns: [
{data: 'escuela', name: 'escuela'},
{data: 'curso', name: 'curso'},
// $.each(version_anio, function(index, value) { <---- looping failed
// {data:'version_anio', name:'version_anio'},
// )},
],language: {
url: '//cdn.datatables/plug-ins/2.1.4/i18n/es-MX.json',
},
});
Share
Improve this question
asked Nov 20, 2024 at 4:21
Rodrigo CabreraRodrigo Cabrera
1072 silver badges10 bronze badges
1 Answer
Reset to default 0I found a non-dynamic solution , I get the results on the Datatable, but in case a new year_version(version_anio) appears it will stuck.
//DATATABLE PRINCIPAL
var table = $('#tabla-resumen').DataTable({
processing: false,
serverSide: false,
ajax: '{{ route("admin/resumen_anual") }}',
dom: 'Bfltip',
columns: [
{data: 'escuela', name: 'escuela'},
{data: 'curso', name: 'curso'},
{data: 'version_anio.0.value'}, <--- I couldn't loop to deliver this
{data: 'version_anio.1.value'}, <--
{data: 'version_anio.2.value'}, <--
{data: 'version_anio.3.value'}, <--
{data: 'version_anio.4.value'}, <--
{data: 'version_anio.5.value'}, <--
{data: 'version_anio.6.value'}, <--
],language: {
url: '//cdn.datatables/plug-ins/2.1.4/i18n/es-MX.json',
},
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742382301a4433362.html
评论列表(0条)