简体   繁体   中英

Datatable copy is not working properly due to some character

I am using Datatable on one of my project. Issue is that Copy is not working due to some special characters. When I am click to copy button and pasting it to excel it is not showing in correct format. Pls check the example link - https://jsfiddle.net/bhaskarjuly26/ssLbeuqL/3/

In the example, first row has two fields name and position which value has javascript code.

I have also tried below code but not working:

  var buttonCommon = {
        exportOptions: {
            format: {
                body: function ( data, column, row ) {
                   var filterData = data.replace( /&lt;/, '<' )
                   return  filterData.replace( /&gt;/, '>' );

                }
            }
        }
    };

To Clear the Issue I am giving the screenshot enter image description here Output should be same in Excel as visible in the screenshot of Step 1

It think this is what you need.

$(document).ready(function() {

var buttonCommon = {
    exportOptions: {
        format: {
            body: function ( data, column, row ) {
               var filterData = data.replace( /&lt;/g, '<' )
               return  filterData.replace( /&gt;/g, '>' );

            }
        }
    }
};

$('#example').DataTable( {
    dom: 'Bfrtip',
     buttons: [
        $.extend( true, {}, buttonCommon, {
            extend: 'copyHtml5'
        } ),
        $.extend( true, {}, buttonCommon, {
            extend: 'excelHtml5'
        } ),
        $.extend( true, {}, buttonCommon, {
            extend: 'pdfHtml5'
        } )
    ]
   } );
   } );

Check jsfiddle here: https://jsfiddle.net/ssLbeuqL/8/

在此处输入图片说明

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