如何从自定义按钮调用 Datatable csv 按钮 [英] How to call Datatable csv button from custom button

查看:16
本文介绍了如何从自定义按钮调用 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>

不是从数据表按钮调用它,我想要上面按钮的相同功能.

Instead of calling it from the Datatable button, i want the same functionality from the above button.

在数据表中寻找一些配置更改,以便我可以调用我的自定义按钮将表记录导出为 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.

在数据表配置中,我为要触发的按钮添加了点击事件.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆