tdundefined / td in child rows datatables

0

I have a list of orders, which in turn have sub-orders. the list of sub-orders, I'm doing it with row child (row details). It works well, the issue is that some fields in the table appear as undefined and in others the data appears correctly.

I have tried the mysql query and it works, the chrome console shows me correctly the json received and it is valid in jsonlint.com and it is correct.

The code is:

function format ( d ) {

 $.ajax({
    type: 'GET',
    url: 'listar2xxx.php',
    dataType: 'json',

});

return '<table class="table table-bordered table-hover dt-responsive display nowrap" width="100%">'+
    '<tr class="alignRight">'+
        '<td>Etapa</td>'+
        '<td>Folio</td>'+
        '<td>Nombres</td>'+
        '<td>Apellidos</td>'+
        '<td>Estado Pedido</td>'+
        '<td>Estado Lab</td>'+
        '<td>Info Pedido</td>'+
    '</tr>'+
    '<tr class="alignRight">'+
        '<td>'+d.etapa+'</td>'+
        '<td>'+d.correlativo+'</td>'+
        '<td>'+d.nombres+'</td>'+
        '<td>'+d.apellidos+'</td>'+
        '<td>'+d.estado_pedido+'</td>'+
        '<td>1</td>'+
        '<td>1</td>'+
    '</tr>'+
'</table>'; 
}

$('#listado tbody').on('click', 'td.details-control', function () {
    table = $('#listado').DataTable();
    var tr = $(this).closest('tr');
    var row = table.row(tr);

    if ( row.child.isShown() ) {
        // This row is already open - close it
        row.child.hide();
        tr.removeClass('shown');
    }
    else {
        // Open this row
        row.child( format(row.data()) ).show();
        tr.addClass('shown');
    }
} );

It should be noted that the call to child rows is being made with ajax independent of the data contained in the table generated in datatables.

My mysql query is:

<?php
$sql = "
SELECT
etapas.token,
etapas.etapa,
etapas.estado_etapa,
etapas.id,
pedidos.nombres,
pedidos.apellidos,
pedidos.tipo_trat,
pedidos.cliente,
pedidos.correlativo

FROM etapas

INNER JOIN pedidos ON (etapas.token = pedidos.token)

WHERE

pedidos.tipo_trat = 2 and pedidos.cliente = '$id' and etapas.etapa <> 1";

$resultado = mysqli_query($conexion, $sql);
if (!$resultado){
    die("Error");
}else{
    while ($data = mysqli_fetch_assoc($resultado)){
        $arreglo["data"][]= $data;
    }
    echo json_encode($arreglo);
}

mysqli_free_result($resultado);
mysqli_close($conexion);

I hope you can help me because for more than reviewing I find no errors in code or the console.

Edited (JSon)

{ "data": [{ "token": "ho381b6zfrdn3c5tb4jd9pve5k8byaq2s7agi8lxa9m5wbu0e", "etapa": "2", "estado_etapa": "A", "id": "4", "nombres": "Hector Mario", "apellidos": "Henriquez Barrios", "tipo_trat": "2", "cliente": "9", "correlativo": "35" }, { "token": "8c5789omesd10zlaxtda3pf8g55ucqrkn2ij9vaycw774bah6", "etapa": "2", "estado_etapa": "A", "id": "6", "nombres": "Sonia", "apellidos": "Gonzalez", "tipo_trat": "2", "cliente": "9", "correlativo": "37" }] }
    
asked by maha1982 08.08.2017 в 06:43
source

0 answers