-1

I have a Datatable in my website and I want carry out certain actions like exporting csv, excel, printing, etc. but certain values in the table appear as icons thereby making datatable not to export the values.

here an example

<table>
   <tr>
      <td>Name: Sammy</td>
      <td>email: Sammy@mail.com</td>
      <td><a href="https://instagram.com/sammy"><i class="fas fa-instagram"></i></a></td>
   <tr>
</table>

So now when I try to export, I want the Instagram link exported too. but Datatable does not capture that. How can I make this work?

samezedi
  • 621
  • 5
  • 15

1 Answers1

0

Default export only supports two different formats i.e., Numbers and InlineString

To resolved this issue there are many ways and alternatives, you may try any of them which are as follows:

  • Try to adjust the exports using the customize options provided by the datatTables here

Try this code for customize options,

customize: function(xlsx) {
    var sheet = xlsx.xl.worksheets['sheet1.xml'];
    // Loop over all cells in sheet
    $('row c', sheet).each( function () {
        // if cell starts with http
        if ($('is t', this).text().indexOf("http") === 0) {
            // (2.) change the type to `str` which is a formula
            $(this).attr('t', 'str');
            //append the formula
            $(this).append('<f>' + 'HYPERLINK("'+$('is t', this).text()+'","'+$('is t', this).text()+'")'+ '</f>');
            //remove the inlineStr
            $('is', this).remove();
            // (3.) underline
            $(this).attr( 's', '4' );
        }
    });
}
  • You may try with the HYPERLINK formula using the hotkeys

  • You may also try with the different export options which can be found on the threads here and here

  • If these all options do not work then you may also try with the PHPExcel ref by dataTables forum for export options, Here is the stackOverflow answer

Hope this helps...

Hetal N
  • 158
  • 8