Estou tentando pegar um json de uma requisição AJAX para inseri-lo na tabela porém sempre que executo o table.rows.add
Código da Tabela:
<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%"> <thead> <tr> <th>Id</th> <th>Uniforme</th> <th>Modelo</th> <th>Tamanho</th> <th>Cor</th> <th>Fornecedor</th> <th>Contrato</th> <th>Quantidade</th> <th>Custo</th> <th>Localização</th> <th class="disabled-sorting text-right">Actions</th> </tr> </thead> <tfoot> <tr> <th>Id</th> <th>Uniforme</th> <th>Modelo</th> <th>Tamanho</th> <th>Cor</th> <th>Fornecedor</th> <th>Contrato</th> <th>Quantidade</th> <th>Custo</th> <th>Localização</th> <th class="disabled-sorting text-right">Actions</th> </tr> </tfoot> <tbody class="tbody"> <tr> <td>aaaa</td> <td>aaaa</td> <td>aaaa</td> <td>aaaa</td> <td>aaaa</td> <td>aaaa</td> <td>aaaa</td> <td>aaaa</td> <td>aaaa</td> <td>aaaa</td> <td class="text-right"> <a href="#" class="btn btn-simple btn-info btn-icon like"><i class="material-icons">favorite</i></a> <a href="#" class="btn btn-simple btn-warning btn-icon edit"><i class="material-icons">dvr</i></a> <a href="#" class="btn btn-simple btn-danger btn-icon remove"><i class="material-icons">close</i></a> </td> </tr> </tbody> </table>
Jquery:
$ ('#datatables').DataTable({ "pagingType": "full_numbers", "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ], responsive: true, language: { search: "_INPUT_", searchPlaceholder: "Search records", }, columns: [ { data: 'Id' }, { data: 'Uniforme' }, { data: 'Modelo' }, { data: 'Tamanho' }, { data: 'Cor' }, { data: 'Fornecedor' }, { data: 'Contrato' }, { data: 'Quantidade' }, { data: 'Custo' }, { data: 'Localização' } ] }); $ .get("http://localhost/infinity/assets/php/list-uniforms.php", function(data){ uniforms = JSON.parse(data); console.log(uniforms); table.rows.add(uniforms).draw(); });
Resultado: