2014-12-21 8 views
6

sto facendo l'elaborazione lato server utilizzando jQuery datatable.My codice DataTable è come di seguito:esportare tutti i dati della tabella utilizzando jQuery DataTable TableTools

$('#DataGrid').dataTable({ 
    destroy: true, 
    "processing": true, 
    searching: false, 
    serverSide: true, 
    "scrollX": true, 
    "bLengthChange": false, 
    "iDisplayLength": pageSize, 
    "bInfo": true, 
    //stateSave: true, 
    order: [ 
     [0, "desc"] 
    ], 
    "aoColumnDefs": [{ 
     'bSortable': false, 
     'aTargets': [(lastColumn - 1)] 
    }], 
    "dom": 'T<"clear">lfrtip', 
    "tableTools": { 
     "aButtons": [ 
      "copy", 
      "csv", "xls", "pdf" 
     ], 
     "sSwfPath": $("body").attr("data-project-root") + "Content/TableTools-2.2.3/swf/copy_csv_xls_pdf.swf" 

    }, 
    ajax: { 
     url: 'StudentProgramListForIdCardResult', 
     type: 'POST', 
     data: function(d) { 
      d.programId = programId; 
      d.sessionId = sessionId; 
      d.branchId = branchId; 
      d.campusId = campusId; 
      d.batchName = batchName; 
      d.course = course; 
      if ($('#paymentStatus').val() > 0) { 
       d.paymentStatus = $('#paymentStatus').val(); 
      } else { 
       d.paymentStatus = paymentStatus; 
      } 
      if ($('#imageStatus').val() > 0) { 
       d.imageStatus = $('#imageStatus').val(); 
       $('#imageStatus').val(); 
      } else { 

       d.imageStatus = imageStatus; 

      } 
      if ($('#printingStatus').val() > 0) { 
       d.printingStatus = $('#printingStatus').val(); 
      } else { 
       d.printingStatus = printingStatus; 
      } 
      d.informationViewList = informationViewList; 
      d.batchDays = batchDays; 
      d.batchTime = batchTime; 
     } 
    } 
}); 

Ma quando ho esportare i dati, TableTools sta esportando i dati in pagina corrente. Non sta caricando tutti i dati nella tabella.

risposta

1

Il plugin DataTable è grande e tutti, ma i sottostanti tavolo/righe della tabella sono ancora lì nel DOM e può essere percorsa nello stesso modo che ci si attraversare qualsiasi tabella HTML:

//foo will be a nodeList of all the tr's in the table 
var foo = document.getElementById('#DataGrid').querySelectorAll('tr'); 

var i = 0, string = '', len = foo.length, row, cells; 

for (;i<len; ++i) { 
    row = foo[i]; 
    cells = row.children; //td's 
    string += 'however you want to package it for your ajax'; 
} 

$.post({url: 'myServerScript', {data: string}, callback}); 

ero in grado per trovare facilmente qualsiasi documentazione su un'esportazione appropriata implementata da plugin, tutti gli esempi di esportazione sembrano concentrarsi su excel/csv salvati sull'unità locale.

+0

dove implementare il codice sopra? In dataTable.js o file sorgente diretto? – PoliDev

+1

In qualsiasi file js che si sta allegando alla propria webapp. Potresti impacchettarlo come metodo e aggiungerlo al prototipo del costruttore Datatable in dataTable.js, ma probabilmente è eccessivo. Dipende da quanto di un purista OO ti capita di essere. –