需要从我的自定义按钮调用 csv 按钮。
<button value="Export report to Excel" class="button-default datatable-csv" type="button" id="ExportReporttoExcel">
<span>Export report to Excel</span>
</button>
我不想从数据表按钮调用它,而是希望从上面的按钮获得相同的功能。
在 Datatable 中寻找一些配置更改,以便我可以调用我的自定义按钮将表记录导出为 csv。
var table=$('#tableId').DataTable( {
"paging": true,
"info": true,
"searching": true,
,buttons: true
});
$("#SEARCH").on("keyup search input paste cut", function() {
table.search(this.value).draw();
});
var buttons = new $.fn.dataTable.Buttons(table, {
buttons: [
'csvHtml5'
]
}).container().appendTo($('#ExportReporttoExcel'));
获得如下输出,但我只需要一个按钮。
原文由 MPPNBD 发布,翻译遵循 CC BY-SA 4.0 许可协议
最后我找到了解决方案。
在数据表配置中,我为要触发的按钮添加了点击事件。
这对我来说很好,感谢您的评论和回答