Problema con funcion callback en DataTables

Problema con funcion callback en DataTables

PzunigaPzuniga Posts: 1Questions: 1Answers: 0
edited July 2023 in Free community support

Tengo una DataTable en la cual quiero editar 2 celdas con un campo tipo list, con las opciones desde BD, pero no llena las opciones

// Archivo bod_cmb_opciones_grilla.php
<?php
    session_start();
    include_once('../../librerias/securitiza.php');

    $conn = oci_pconnect($_SESSION['salud_pub_user'],$_SESSION['salud_pub_pass'],$_SESSION['salud_pub_serv'], 'AL32UTF8');
    
    $estab = $_SESSION['salud_pub_estab'];
    $column = $_POST['column'];

    define('VIGENTE',1);
    $vigente=VIGENTE;

    switch ($column) {
        case 4:
            $consulta ="SELECT 
                            ID as value, NOMBRE as display
                        FROM 
                            BOD_SYS_CENTRO_COSTO
                        WHERE 
                            ESTADO=:vigente
                            AND EST_COD=:estab 
                        UNION
                        SELECT 
                            ID as value, NOMBRE as display
                        FROM 
                            BOD_SYS_CENTRO_COSTO C 
                        WHERE 
                            ESTADO=:vigente AND ID=0    
                        ORDER BY 2 ASC";
                $st=oci_parse($conn,$consulta);
                oci_bind_by_name($st, ':estab', $estab) or die("Establecimiento no definida");
                oci_bind_by_name($st, ':vigente', $vigente) or die("vigente no definida");
            break;
        case 6:
            $consulta = "SELECT ID as value, GLOSA AS display
                        FROM BOD_SYS_OPCIONES 
                        WHERE ID_CONTROL='programa' AND ESTADO=:vigente
                        ORDER BY GLOSA ASC";
            $st=oci_parse($conn,$consulta);
            oci_bind_by_name($st, ':vigente', $vigente) or die("vigente no definida");
            break;
    }
                
    oci_execute($st);

    $options = array();

    while($data=oci_fetch_array($st,OCI_ASSOC)){
        $options[] = array(
            "value" => $data['VALUE'],
            "display" => $data['DISPLAY']
        );
    }

    oci_free_statement($st);
    oci_close($conn);

    header('Content-Type: application/json');
    echo json_encode($options);


<?php
>
```
?>



// Codigo js

var grid_ocompraFonendo = $("#grid_ocompra_fonendo").DataTable({
ajax: "views/bod_carga_ocompra_mc_pendientes.php",
responsive: true,
paging: true,
scrollCollapse: true,
scrollY: '50vh',
destroy: true,
searching: true,
orderClasses: true,
columns: [
{ "data": "FOLIO_OC" },
{ "data": "FECHA_OC" },
{ "data": "FOLIO_CHC" },
{ "data": "COD_CENTRO_COSTO","visible":false },
{ "data": "CENTRO_COSTO" },
{ "data": "COD_PROGRAMA","visible":false },
{ "data": "PROGRAMA" },
{ "data": "RUT_PROVEEDOR","visible":false },
{ "data": "PROVEEDOR" },
{ "data": "ESTADO",
"render": function(data, type, row) {
estado_oc=data;
switch (data) {
case '99':
return '<i class="fab fa-product-hunt fa-5x" style="color:red;font-size: 20px;" data-toggle="tooltip" data-placement="left" title="Pendiente"></i>';
}
}
},
{ "data": "DETALLE","visible":false },
{ "data": "FOLIO_OC",
"render": function(data, type, row) {
return "<button type='button' class='detalle_ocompraFonendo btn btn-info' title='Detalle Orden Compra Cargada'><i class='fas fa-search'></i></button>";
}
}
],
select: {
"style": "single"
},
"createdRow": function( row, data, dataIndex ) {
$(row).attr("id", data["FOLIO"]);
},
language: {
"decimal": "",
"emptyTable": "No hay información",
"info": "Mostrando START a END de TOTAL Entradas",
"infoEmpty": "Mostrando 0 a 0 de 0 Entradas",
"infoFiltered": "(Filtrado de MAX total entradas)",
"infoPostFix": "",
"thousands": ",",
"lengthMenu": "Mostrar MENU Entradas",
"loadingRecords": "Cargando...",
"processing": "Procesando...",
"search": "Buscar:",
"zeroRecords": "Sin resultados encontrados",
"select": {
"rows": "<br/>%d Perfiles Seleccionados"
},
"paginate": {
"first": "Primero",
"last": "Ultimo",
"next": "Sig.",
"previous": "Ant."
}
}
});

function getOptionsFromServer(column, callback) {
    $.ajax({
        url: "views/bod_cmb_opciones_grilla.php",
        data: { column: column },
        dataType: 'json',
        success: function(data) {
            callback(data);
        }
    });
}

function myCallbackFunction (updatedCell, updatedRow, oldValue) {

}

grid_ocompraFonendo.MakeCellsEditable({
    "onUpdate": myCallbackFunction,

    "inputCss":'my-input-class',
    "columns": [4,6],
    "allowNulls": {
        "columns": [4,6],
        "errorClass": 'error'
    },
    "inputTypes": [
        {
            "column": 4,
            "type": "list",
            "onSourceReady": getOptionsFromServer
        },
        {
            "column": 6,
            "type": "list",
            "onSourceReady": getOptionsFromServer
        }
    ]
});

```

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.