error para refrescar un datatable

error para refrescar un datatable

odalmysodalmys Posts: 1Questions: 1Answers: 0
edited May 2019 in Free community support

hola, este es mi codigo que ejecuto para crear una datatable dinamica, hago una peticion que ejecuta una funcion donde realizo una consulta a la BD arroja un arreglo de clientes, donde luego pinto el resultado en un datatable.

y quiero refrescar el datatable cuando cierro un modal que tengo para adicionar, que es un modal aparte, y me da error.

que puedo hacer?

gracias!

$.ajax({
        type: 'GET',
        url: 'MAX_SOLICITUDES/peticiones_solicitudc.php',
        data: {accion: '90'},
        success: function (datos) {

            var obj = jQuery.parseJSON(datos);
            console.log(obj);
            var personalidad;

            if (obj.length == undefined) {
                console.log('no existen valores');
            } else {

                obj.forEach(function (obj, index) {
                    if (obj['ID_Personalidad'] == 1) {
                        personalidad = 'Persona Fisica';
                    } else if (obj['ID_Personalidad'] == 2) {
                        personalidad = 'Persona Moral';
                    } else if (obj['ID_Personalidad'] == 3) {
                        personalidad = 'Amabas';
                    } else if (obj['ID_Personalidad'] == 0) {
                        personalidad = 'Sin Definir';
                    }

                    var fila = '<tr id="td_' + index + '">' +
                            '<td><div class="dropdown">' +
                            '<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"><span class = "glyphicon glyphicon-align-justify" height: 19px;"></span></button>' +
                            '<ul class="dropdown-menu">' +
                            '<li><a id="editar_' + index + '"><span class = "glyphicon glyphicon-pencil" height: 19px;"></span>Editar</a></li>' +
                            '<li> <a id="eliminar_' + index + '"><span class = "glyphicon glyphicon-trash" height: 19px;"></span>Eliminar</a></li>' +
                            '</ul>' +
                            '</div></td>' +
                            '<td style="text-align: center;" colspan="1" rowspan="1" class="td" id="ID_Contribuyente_' + index + '"><span style="font-weight:bold;" ></span> ' + obj['ID_Contribuyente'] + '</td>' +
                            '<td style="text-align: center;" colspan="1" rowspan="1" class="td" id="ID_Personalidad_' + index + '"><span style="font-weight:bold;" ></span> ' + personalidad + '</td>' +
                            '<td style="text-align: center;" colspan="1" rowspan="1" class="td" id="RFC_' + index + '"><span style="font-weight:bold;"></span>' + obj['RFC'] + '</td>' +
                            '<td style="text-align: center;" colspan="1" rowspan="1" class="td" id="nommbrecompleto_' + index + '"><span style="font-weight:bold;" ></span> ' + obj['Nombre_Contribuyente'] + '</td>' +
                            '</tr>';

                    $('.tbcontribuyentes').append(fila);

                });


                $('#table_id').DataTable({
                
                    columnDefs: [{

                            targets: [0],

                            orderData: [0, 1]

                        }, {

                            targets: [1],

                            orderData: [1, 0]

                        }, {

                            targets: [3],

                            orderData: [3, 0]

                        }],
           
                    stateSave: true,

                    "language": {

                        "sProcessing": "Procesando...",

                        "sLengthMenu": "Mostrar _MENU_ registros",

                        "sZeroRecords": "No se encontraron resultados",

                        "sEmptyTable": "Ningún dato disponible en esta tabla",

                        "sInfo": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",

                        "sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",

                        "sInfoFiltered": "(filtrado de un total de _MAX_ registros)",

                        "sInfoPostFix": "",

                        "sSearch": "Buscar:",

                        "sUrl": "",

                        "sInfoThousands": ",",

                        "sLoadingRecords": "Cargando...",

                        "oPaginate": {

                            "sFirst": "Primero",

                            "sLast": "Último",

                            "sNext": "Siguiente",

                            "sPrevious": "Anterior"

                        },

                        "oAria": {

                            "sSortAscending": ": Activar para ordenar la columna de manera ascendente",

                            "sSortDescending": ": Activar para ordenar la columna de manera descendente"

                        }

                    },

                });

                $('#table_id tbody').on('click', 'tr', function () {
                    var codigo = $('td', this).eq(0).text();

                    var nombre = $('td', this).eq(1).text();
                    console.log('Codigo del cliente ' + codigo + ' ' + 'Nombre ' + nombre);

                });



            }
        }
    });

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @odalmys ,

    You didn't say what error you're seeing. 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

This discussion has been closed.