No se puede reinicializar DataTable

No se puede reinicializar DataTable

veronicaschlomitveronicaschlomit Posts: 1Questions: 1Answers: 0
edited May 2021 in DataTables

Buenas noches

Tengo el siguiente problema de Inicializacion de dataTable, mi tabla tiene varias funciones, buscador por rango de fecha, cambio el lenguaje de ingles a español, exportar a excel, pdf, pero cada vez que recargo la pagina me aparece el error :

Advertencia de DataTables: id de tabla = ejemplo: no se puede reinicializar DataTable. Para obtener más información sobre este error, consulte http://datatables.net/tn/3

Segun la pagina " http://datatables.net/tn/3", hay que destruir la primera funcion, pero de ser así quedaria sin funcionamiento las otras solicitudes de accion.

Este es mi código, cada vez que selecciono la fecha y presiono buscar la primera vez funciona si deseo volver a buscar me arroja el error-.

cual es la solución? e intentado destruir pero no funciona del todo.-

$('button[id=buscar]').click(function(){


       // function fetch(f_desde,f_hasta){

        var x = $("#f_desde").val();
        var fecha_d = x.split('/');
        var f_desde = fecha_d[2]+fecha_d[1]+fecha_d[0];

        var f = $("#f_hasta").val();
        var fecha_h = f.split('/');
        var f_hasta = fecha_h[2]+fecha_h[1]+fecha_h[0];


            $.ajax({
                url: "SelectReporte",
                type: "POST",
                data:{
                    f_desde: f_desde,
                    f_hasta: f_hasta
                },
                dataType: "json",

                success: function(data){
                    console.log(data);
                    //alert(data);

                  

               reporte = $('#reporte').DataTable({  

                language: {
                    "decimal": "",
                    "emptyTable": "No hay información",
                    "info": "Mostrando _START_ a _END_ de _TOTAL_ Entradas",
                    "infoEmpty": "Mostrando 0 to 0 of 0 Entradas",
                    "infoFiltered": "(Filtrado de _MAX_ total entradas)",
                    "infoPostFix": "",
                    "thousands": ",",
                    "lengthMenu": "Mostrar _MENU_ Entradas",
                    "loadingRecords": "Cargando...",
                    "processing": "Procesando...",
                    "search": "Buscar:",
                    "zeroRecords": "Sin resultados encontrados",
                    "paginate": {
                        "first": "Primero",
                        "last": "Ultimo",
                        "next": "Siguiente",
                        "previous": "Anterior"
                    }
                },
                    responsive: "true",
                    dom: 'Bfrtip',
                    buttons: [

                        {
                            extend:     'excelHtml5',
                            text:       '<i class="fas fa-file-excel"></i>',
                            tittleAttr: 'Exportar a Excel',
                            className:  'btn btn-success'
                        },

                        {
                            extend:     'pdfHtml5',
                            text:       '<i class="fas fa-file-pdf"></i>',
                            tittleAttr: 'Exportar a PDF',
                            className:  'btn btn-danger'
                        },

                        {
                            extend:     'print',
                            text:       '<i class="fas fa-print"></i>',
                            tittleAttr: 'Imprimir',
                            className:  'btn btn-info'
                        },
                    ],

                    "data":data,
                    "columns":[
                        {"data": "fecha"},
                        {"data": "plan_nombre"},
                        {"data": "rut"},
                        {"data": "nombre"},
                        {"data": "edad"},
                        {"data": "pac_correo"},
                        {"data": "pac_movil"},
                        {"data": "fpago_nombre"},
                        {"data": "mod_nombre"},
                        {"data": "tipo_af"}
                    ],

                        //mostrar = $('#reporte').DataTable();

              });

               //reporte.destroy();
                }


            });

      });*: 

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

Answers

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

    You could try retrieve when you initialise the table, or possibly destroy.

    If that doesn't help, 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.