如何跳过数据表导出选项中的最后一行(.csv pdf选项)

我的脚本在下面。 我想跳过我的最后一行excel和pdf。

$('.data-grid-export').DataTable({ dom: 'Blfrtip', buttons: [ { extend: 'pdf', footer: true, }, { extend: 'excel', footer: false } ] }); 

尝试使用例如initComplete向最后一行添加类或标识:

 initComplete : function(){ $(".data-grid-export tr").last().addClass("notPrintable"); } 

然后使用buttons的exportOptions选项指定除class / id之外的所有行:

 buttons:[ { extend: 'pdf', exportOptions:{ rows: ':not(.notPrintable)' } } 

这在我的桌子上工作,希望它可以帮助你

用户自定义选项导出Excel的简单示例如下所示:

 customize: function (xlsx) { var sheet =xlsx.xl.worksheets['sheet1.xml']; $('row', sheet).filter(function () { var attr = $(this).attr('r'); if (attr == $('row', sheet).length) //last row return true; return false; }).remove(); } 
Interesting Posts