function table2csv(oTable, exportmode, tableElm) {
var csv = '';
var headers = [];
var rows = [];
// Get header names
$(tableElm+' thead').find('th').each(function() {
var $th = $(this);
var text = $th.text();
var header = '"' + text + '"';
// headers.push(header); // original code
if(text != "") headers.push(header); // actually datatables seems to copy my original headers so there ist an amount of TH cells which are empty
});
csv += headers.join(',') + "\n";
// get table data
if (exportmode == "full") { // total data
var total = oTable.fnSettings().fnRecordsTotal()
for(i = 0; i ');
}
function strip_tags(html) {
var tmp = document.createElement("p");
tmp.innerHTML = html;
return tmp.textContent||tmp.innerText;
}
函数支持导出所有数据和当前页数据
// export only what is visible right now (filters & paginationapplied)
$('#export_visible').click(function(event) {
var oTable;
oTable= $('#spdata').dataTable();
event.preventDefault();
table2csv(oTable, 'visible', '#spdata'); })
// export all table data
$('#export_all').click(function(event) {
var oTable;
oTable= $('#spdata').dataTable();
event.preventDefault();
table2csv(oTable, 'full', '#spdata'); })