如何使用导出excel并打印数据表中的选定列? [英] How to use export excel and print for selected columns in datatable?

查看:17
本文介绍了如何使用导出excel并打印数据表中的选定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用导出 excel 并打印数据表.我使用以下代码,但无法对所选列同时使用这两个选项.

I want to use export excel and print the datatable .I use following code but not able to use both options for selected columns.

$('#example').DataTable( {
    dom: 'Blfrtip',
                buttons: [
                        {
                    extend: 'excel','print',

                    exportOptions: {
                        columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
                    },

                }

                ],


                "lengthMenu": [[200, 250, 500, -1], [200, 250, 500, "All"]],
                 "bLengthChange" : true,


    initComplete: function () {
        this.api().columns().every( function () {
            var column = this;
            var select = $('<select><option value="">Select</option></select>')
                .appendTo( $(column.footer()).empty() )
                .on( 'change', function () {
                    var val = $.fn.dataTable.util.escapeRegex(
                        $(this).val()
                    );

                    column
                        .search( val ? '^'+val+'$' : '', true, false )
                        .draw();
                } );

            column.data().unique().sort().each( function ( d, j ) {
                select.append( '<option value="'+d+'">'+d+'</option>' )
            } );
        } );
    }
} );

我不知道发生了什么问题.请帮助我.

I am not figure out what happens wrong.Please help me.

推荐答案

{
 extend: 'excel'
 exportOptions: {
 columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
},
{
 extend: 'print'
 exportOptions: {
 columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
}

这篇关于如何使用导出excel并打印数据表中的选定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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