使用数据表中的复选框导出选定的行。
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{
"sExtends": "csv",
"bSelectedOnly": true
}
]
},
"order": [[ 1, "desc" ]],
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"columnDefs": [
{
"targets": 0,
render: function ( data, type, row ) {
return row[5]?'':'<input type="checkbox" value="'+row[4]+'">'
}
}
]
});
第一期 - 页面上未显示导出按钮。
第二期 - 如何正确实现此代码以导出选定的行。
我使用普通的 DOM 数据源作为数据表。
您尝试过这个网址吗?里面有提到导出功能
$('#example').dataTable({
dom: 'Bfrtip',
buttons: [{
extend: 'excelHtml5',
title: '',
exportOptions: {
format: {
body: function(data, row, column, node) {
var checkbox = node.previousSibling;
if (column === 0 && ($(checkbox).children()[0].checked)) {
localStorage.setItem('isSameRow', row);
var nodef = $(node).children()[0];
}
var isSameRow = localStorage.getItem('isSameRow');
if (row == isSameRow) {
return data;
}
}
}
}
}, ]
});