laravel - How display nested array in Yajra datatable - Stack Overflow

I have an array that contains two sub-arrays, one called "version_anio"and another called &qu

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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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

相关推荐

  • laravel - How display nested array in Yajra datatable - Stack Overflow

    I have an array that contains two sub-arrays, one called "version_anio"and another called &qu

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信