2

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

4

1 回答 1

1

这是DataTables的人正在处理的错误,同时我以这种方式解决了它,如果其他人知道这样做的更好方法,请告诉我

  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);
      });
于 2017-05-03T09:56:14.953 回答