简体   繁体   English

Javascript数据表插件

[英]Javascript datatables plugin

I am using the Javascript datatables plugin: https://datatables.net Is it possible to specify the column type when exporting data to excel? 我正在使用Javascript datatables插件: https ://datatables.net在将数据导出到Excel时是否可以指定列类型? I want to specify a certain column to be a time format in the final excel document. 我想在最终的Excel文档中指定某个列作为时间格式。 I have looked at the documentation: https://datatables.net/manual/index but I can't find any solution. 我查看了文档: https//datatables.net/manual/index但我找不到任何解决方案。

Yes, There is a function called columns.render which does exactly this. 是的,有一个名为columns.render的函数正是这样做的。

Buttons has two different methods that can be used to format the data exported differently from the data that is shown in the table: orthogonal options as shown in this example and formatting functions. 按钮有两种不同的方法可用于格式化导出的数据与表中显示的数据不同:正交选项如本例所示和格式化函数。 They both achieve basically the same thing in different ways: namely modification of the output data. 它们都以不同的方式实现了基本相同的东西:即输出数据的修改。

$(document).ready(function() {
    $('#example').DataTable( {
        ajax: '../../../../examples/ajax/data/objects.txt',
        columns: [
            { data: 'name' },
            { data: 'position' },
            { data: 'office' },
            { data: 'extn' },
            { data: 'start_date' },
            { data: 'salary', render: function (data, type, row) {
                return type === 'export' ?
                    data.replace( /[$,]/g, '' ) :
                    data;
            } }
        ],
        dom: 'Bfrtip',
        buttons: [
            {
                extend: 'copyHtml5',
                exportOptions: { orthogonal: 'export' }
            },
            {
                extend: 'excelHtml5',
                exportOptions: { orthogonal: 'export' }
            },
            {
                extend: 'pdfHtml5',
                exportOptions: { orthogonal: 'export' }
            }
        ]
    } );
} );

Referred from https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html 参考https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM