如何从自定义按钮调用Datatable csv按钮 [英] How to call Datatable csv button from custom button
本文介绍了如何从自定义按钮调用Datatable csv按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要从我的自定义按钮调用csv按钮。
Need to call csv button from my custom button.
<button value="Export report to Excel" class="button-default datatable-csv" type="button" id="ExportReporttoExcel">
<span>Export report to Excel</span>
</button>
我没有从Datatable按钮调用它,而是想从上面的按钮获得相同的功能。
Instead of calling it from the Datatable button, i want the same functionality from the above button.
在Datatable中寻找一些配置更改,以便我可以调用我的自定义按钮将表记录导出为csv。
Looking for some configuration changes in Datatable so that i can call my custom button to export the table records as 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'));
获得如下输出,但我只需要一个按钮。
Getting output like below but i need only one button.
推荐答案
最后我找到了解决方案。
At last i found the solution.
在Datatable配置中,我为要触发的按钮添加了点击事件。
In Datatable configuration , i added click event for the button to be triggered.
buttons: [
{
extend: 'csv',
}
]
$("#ExportReporttoExcel").on("click", function() {
table.button( '.buttons-csv' ).trigger();
});
这对我来说很好,感谢您的评论和答案
This works fine for me thanks for the comments and answers
这篇关于如何从自定义按钮调用Datatable csv按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文