jqueryexceldatatablesdatatable-buttons

Datatables Buttons Disapear After Reload


Im trying to make Excel, PDF and Print button, to my Datatables Result, well, i done it, but, when i reload the content of the datatable the excel and Print button disapear,

This is how i Send the information to the datatable

$.ajax({
                    type: 'POST',
                    url: 'Inicio.aspx/ContactsList',
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        FillDataTable(data, 'Listado de Todos');

                    }
                });

Here is the Methot of my datatable

 function FillDataTable(data, reporte) {
                $('#GridActivos').dataTable({
                    dom: 'Bfrtip',
                     destroy: true,
                    buttons: [
                        {
                            extend: 'excel',
                            customize: function (xlsx) {
                                var sheet = xlsx.xl.worksheets['sheet1.xml'];
                                $('row c[r*="10"]', sheet).attr('s', '25');
                            },
                            title: reporte
                        },
                        {
                            extend: 'pdf',
                            title: reporte
                        },
                        {
                            extend: 'print',
                            customize: function (win) {
                                $(win.document.body)
                                    .css('font-size', '10pt')
                                    .prepend(
                                        '<img src="http://datatables.net/media/images/logo-fade.png" style="position:absolute; top:0; left:0;" />'
                                    );

                                $(win.document.body).find('table')
                                    .addClass('compact')
                                    .css('font-size', 'inherit');
                            },
                            title: reporte
                        },


                    ],
                    select: {
                        style: 'single'
                    },
                    bProcessing: true,
                    "aaData": JSON.parse(data.d),
                    "aoColumns": [
                        { "mDataProp": "ID" },
                        { "mDataProp": "NOMBRES" },
                         { "mDataProp": "Sexo" },
                          { "mDataProp": "Edad" },
                           { "mDataProp": "Puntuacion" },
                            { "mDataProp": "NivelEconomico" },
                             { "mDataProp": "Hacinamiento" },
                                 { "mDataProp": "RelM" },
                                  { "mDataProp": "RelP" },
                             { "mDataProp": "RelT" }

                    ]
                });
            }

here is the image when y press the search button by first time Imagen1

here is when i press again Imagen2


Solution

  • This is an error that the people of DataTables are working on, meanwhile i solve it in that way, if somebody else know a bether way to do this, let me know please

      var buttons = [];
    
      $.each($('#GridActivos').DataTable().buttons()[0].inst.s.buttons,
          function () {
          buttons.push(this);
           });
      $.each(buttons,
          function () {
          $('#GridActivos').DataTable().buttons()[0].inst.remove(this.node);
          });