需要从我的自定义按钮调用 csv 按钮。
<button value="Export report to Excel" class="button-default datatable-csv" type="button" id="ExportReporttoExcel">
<span>Export report to Excel</span>
</button>
我不想从数据表按钮调用它,而是希望从上面的按钮获得相同的功能。
寻找数据表中的一些配置更改,以便我可以调用自定义按钮将表记录导出为 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'));
得到如下输出,但我只需要一个按钮。
最后我找到了解决方案。
在数据表配置中,我添加了单击事件以触发按钮。
buttons: [
{
extend: 'csv',
}
]
$("#ExportReporttoExcel").on("click", function() {
table.button( '.buttons-csv' ).trigger();
});
这对我来说效果很好,感谢您的评论和答案
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)