仅在数据表中导出列标题

时间:2019-05-22 17:28:58

标签: jquery datatables export-to-csv

我正在使用数据表,它允许用户将数据导出为csv。我的问题是如何仅在数据表中导出列标题?我已经在互联网上搜索过,但是找不到任何可靠的来源。这是我以csv格式导出数据表的代码:

/**
         * Datatable
         */
        SML.table = SML.$tbl.DataTable({
            "dom": 'Bfrtip',
            "buttons": [
                {
                extend: 'csv',
                charset: 'UTF-16LE',
                fieldSeparator: ',',
                bom: true,
                exportOptions: {
                        columns: [1,2,3,4,5,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,44 ],
                    }
                }
            ],
            "order": [],
            "processing": true,
            "select": true,
            "iDisplayLength": 25,
            "searching": true,
            "bLengthChange" : true,
            "orderClasses": false,
            "language": {
                "url": "https://cdn.datatables.net/plug-ins/1.10.15/i18n/Japanese.json",
            },
            "columnDefs": [
                {
                "targets"  : [0,7],
                "orderable": false,
                },
                {
                    "targets": [8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,44 ],
                    //if you can suggest some way to shorten this too
                    "visible": false,
                    "searchable": false
                },
            ],
            "drawCallback": function( settings ) {
              SML.$chk_all.iCheck('uncheck');
            },
        });

所以我的输出应该有两个按钮,分别是将数据导出为csv和导出csv模板。

1 个答案:

答案 0 :(得分:0)

就知道了!我只是得到表行的类,并在排除中使用了它:

"buttons": [
  {
    extend: 'csv',
    text : 'Export Template',
    charset: 'UTF-16LE',
    bom: true,
    exportOptions : {
        columns: [1,2,3,4,5,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,44 ],
        rows: ':not([role=row])'
    },
  },
]

希望这对以后的人有帮助。