how can I export my records in multiple excel files

how can I export my records in multiple excel files

angelrzsaangelrzsa Posts: 1Questions: 1Answers: 0

I'm trying to split my data into 2 download files but I can't

var oldExportAction = function(self, e, dt, button, config) 
{
  if (button[0].className.indexOf('buttons-copy') >= 0) 
  {
                $.fn.dataTable.ext.buttons.copyHtml5.action.call(self, e, dt, button, config);
            } else if (button[0].className.indexOf('buttons-excel') >= 0) {
                $.fn.dataTable.ext.buttons.excelHtml5.available(dt, config) ?
                    $.fn.dataTable.ext.buttons.excelHtml5.action.call(self, e, dt, button, config) :
                    $.fn.dataTable.ext.buttons.excelFlash.action.call(self, e, dt, button, config);
            } else if (button[0].className.indexOf('buttons-csv') >= 0) {
                $.fn.dataTable.ext.buttons.csvHtml5.available(dt, config) ?
                    $.fn.dataTable.ext.buttons.csvHtml5.action.call(self, e, dt, button, config) :
                    $.fn.dataTable.ext.buttons.csvFlash.action.call(self, e, dt, button, config);
            } else if (button[0].className.indexOf('buttons-pdf') >= 0) {
                $.fn.dataTable.ext.buttons.pdfHtml5.available(dt, config) ?
                    $.fn.dataTable.ext.buttons.pdfHtml5.action.call(self, e, dt, button, config) :
                    $.fn.dataTable.ext.buttons.pdfFlash.action.call(self, e, dt, button, config);
            } else if (button[0].className.indexOf('buttons-print') >= 0) {
                $.fn.dataTable.ext.buttons.print.action(e, dt, button, config);
            }
};




 var newExportAction = function(e, dt, button, config) 
{
    var self = this;


    var oldStart = dt.settings()[0]._iDisplayStart;
    var oldLenght = dt.settings()[0]._iDisplayLength;


    var info = dt.page.info();

    var total_registros = info.pages * 25;
    //Total de archivos a descargar
    var total_archivos_descargar = 2;
    //Registros por archivo
    var registros_por_archivo = Math.round(total_registros / total_archivos_descargar);

    for (var i = 1; i <= total_archivos_descargar; i++) 
    {

        dt.start = (i - 1) * ( registros_por_archivo + (i - 1) ); 
        dt.length = registros_por_archivo + ( (i - 1) * registros_por_archivo );
        console.log("Vuelta: "+i);
        console.log("<br>"+dt.start);
        console.log("<br>"+dt.length);


        dt.one('preXhr', function(e, s, data) 
        {
            data.start = dt.start;
            data.length = dt.length;


            dt.one('preDraw', function(e, settings) 
            {

                  oldExportAction(self, e, dt, button, config);

                  dt.one('preXhr', function(e, s, data) 
                  {

                    settings._iDisplayStart = oldStart;
                    //Registros que se van a mostrar al redraw la tabla
                    data.start = oldStart;
                  });

                  setTimeout(dt.ajax.reload, 0);

                  return false;
            });
        });        
    }
dt.ajax.reload();
};

Currently downloading 2 files with the same amount of data
Example:
1 File: 2043 to 5000
2 File: 2043 to 5000

But I am changing the limits correctly and they are not changed

Answers

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

    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.