admin管理员组文章数量:1334821
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',
},
});
本文标签: laravelHow display nested array in Yajra datatableStack Overflow
版权声明:本文标题:laravel - How display nested array in Yajra datatable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742382301a2464335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论