Export all table data using jquery dataTables TableTools

I am doing server side processing using jquery datatable.My datatable code is as follows:

$('#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; } } }); 

But when I export the data, TableTools exports the data on the current page. It does not load all the data into a table.

+6
source share
1 answer

The dataTables plugin is great and that’s it, but the main rows of the table / table are still present in the DOM and can be traversed just like in any HTML table:

 //foo will be a nodeList of all the tr 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}); 

I was not able to easily find the documentation for the corresponding export plugin, all export examples seem to focus on excel / csv stored on the local disk.

+1
source

Source: https://habr.com/ru/post/979993/


All Articles