bug?

bug?

Tomas_GajardoTomas_Gajardo Posts: 3Questions: 1Answers: 0

hi:
this is my problem, when i try to load the data on dataTables it stays stuck on loading, so i checked the json is receiving with jsonlint and it is valid, then i checked the debuger and got this:"jquery.dataTables.min.js:45 Uncaught TypeError: Cannot read property 'length' of undefined" on chrome and "TypeError: f is undefined jquery.dataTables.min.js:45:478" on firefox, this is a bug or im doing something wrong?
PS: this is the dataTables debug code:epiwol.
PS2:im using cakephp as framework.
PS3:is a close system so i cant give a link.
Javascript:

$(document).ready(function() {
    $('#example').dataTable( {
        "bProcessing": false,
        "ajax": '/sg_bodega_chica/articulos/relleno',
    } );   
});

HTML(CTP)

<div class="actions columns large-2 medium-3">
    <h3><?= __('Opciones') ?></h3>
    <ul class="side-nav">
        <li><?= $this->Html->link(__('Nuevo Articulo'), ['action' => 'add']) ?></li>
    </ul>
</div>
<div class="articulos index large-10 medium-9 columns">
  <table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>ID</th>
            <th>Serial</th>
            <th>Nombre</th>
            <th>Familia</th>
            <th>SubFamilia</th>
            <th>Estado</th>
            <th>Precio</th>
        </tr>
    </thead>

    <tfoot>
        <tr>
            <th>ID</th>
            <th>Serial</th>
            <th>Nombre</th>
            <th>Familia</th>
            <th>SubFamilia</th>
            <th>Estado</th>
            <th>Precio</th>
        </tr>
    </tfoot>
</table>
</div>

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    You are returning an array of objects in your Ajax. You need to tell DataTables what property applies to each column - documentation.

    Allan

  • Tomas_GajardoTomas_Gajardo Posts: 3Questions: 1Answers: 0

    i still get the same error; this is my new code

    $(document).ready(function() {
            $('#example').dataTable( {
            "ajax": '/sg_bodega_chica/articulos/relleno',
            columns: [
            { data:"ID" },
            { data: "Serial" },
            { data: "Nombre" },
            { data: "Familia" },
            { data: "SubFamilia" },
            { data: "Estado" },
            { data: "Precio" },
            ]
            
        } );
        
    });    
    

    when i try to put data:data it send a msj saying data not defined. im a bit confused data is supposed to be the json name?
    thanks :D

  • Tomas_GajardoTomas_Gajardo Posts: 3Questions: 1Answers: 0

    i just fixed thanks :D

This discussion has been closed.