【问题标题】:Trigger Datatable print from Custom Print Button从自定义打印按钮触发数据表打印
【发布时间】:2018-01-10 00:57:07
【问题描述】:

我在 Bootstrap3 框架中有一个数据表。我想提供一个通过打印按钮打印数据表的选项。

这是我的数据表的 jquery 实例化

$('#dataTables-example').DataTable({
'按钮': ['excel', 'pdf', 'print'] });

但是,打印按钮不适合我的主题,并希望通过自定义打印按钮触发数据表打印功能。知道如何实现吗?

参考:Documentation for Datatable Print

【问题讨论】:

    标签: javascript jquery twitter-bootstrap datatable


    【解决方案1】:

    您应该像这样添加自定义打印按钮事件:

    按钮

    <button id="btnPrint">Custom Print Button</button>
    

    JS

    /* custom button event print */
    $(document).on('click', '#btnPrint', function(){
       $(".buttons-print")[0].click(); //trigger the click event
    });
    

    你可以在这里看到现场演示:https://output.jsbin.com/cozadek

    https://jsbin.com/cozadek/13/edit?html,output

    【讨论】:

    • 非常感谢,真的很有帮助。感谢所有帮助
    • 在引导程序 4 中不起作用,无法读取未定义的属性“点击”
    • @TechPotter 我猜你的问题与页面上没有的实际按钮有关。我目前正在寻找自己的解决方案,因为如果您仍然必须拥有旧按钮,那么自定义按钮显然不是那么好。
    • @TechPotter 你可以添加实际的按钮,并隐藏它。
    猜你喜欢
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 2023-03-26
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    相关资源
    最近更新 更多