简体   繁体   中英

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? I want to specify a certain column to be a time format in the final excel document. I have looked at the documentation: https://datatables.net/manual/index but I can't find any solution.

Yes, There is a function called columns.render which does exactly this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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