how to export csv in IE9

how to export csv in IE9

djsomersdjsomers Posts: 1Questions: 1Answers: 0
edited January 2019 in Free community support

Hello everybody,

This is my first post so thank you in advance for any help that you are able to provide me.

My problem is simple, I need to export my data to .csv format in IE9. The following code works for IE10+ but not IE9. I've spent a day or two looking for a solution as my boss at work requires DataTables to work on IE9 as some of our clients still use that version of the browser.

I've read that you can save to .csv in IE9 but for some reason, I am unable to get the required functionality to work. I'm using Browserstack to test and I'm not getting any errors when I debug in developer tools. I have checked that adobe player is installed as well.

Thanks again.
Daniel

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jqc-1.12.4/jszip-2.5.0/dt-1.10.18/af-2.3.2/b-1.5.4/b-colvis-1.5.4/b-flash-1.5.4/b-html5-1.5.4/b-print-1.5.4/cr-1.5.0/fc-3.2.5/fh-3.1.4/kt-2.5.0/r-2.2.2/rg-1.1.0/rr-1.2.4/sc-1.5.0/sl-1.2.6/datatables.css"/>
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/jszip-2.5.0/dt-1.10.18/af-2.3.2/b-1.5.4/b-colvis-1.5.4/b-flash-1.5.4/b-html5-1.5.4/b-print-1.5.4/cr-1.5.0/fc-3.2.5/fh-3.1.4/kt-2.5.0/r-2.2.2/rg-1.1.0/rr-1.2.4/sc-1.5.0/sl-1.2.6/datatables.js"></script>

</head>
<body>
    <table class="display" id="example" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>
            <tr>
                <td>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</td>
            </tr>
            <tr>
                <td>Ashton Cox</td>
                <td>Junior Technical Author</td>
                <td>San Francisco</td>
                <td>66</td>
                <td>2009/01/12</td>
                <td>$86,000</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table>
</body>
</html> 

<script>
    $(document).ready(function() {

        $('#example').DataTable({
            dom: 'Bfrtip',
            buttons: [

                'copy','excel','pdf','csv'
            ]
        });
    });

</script>
</asp:Content>

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @djsomers ,

    When you say it doesn't work, is the file corrupted or does the download just not happen? Would you be able to attach the file here, please, if it does download?

    Cheers,

    Colin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @djsomers ,

    I just installed a VM with IE9 on and you're right - it's not working - the export button isn't appear for me. I'll log this and get it looked into and report back here once I have an update.

    Cheers,

    Colin

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    IE9 doesn't provide the APIs required to be able to create a file client-side - they were introduced in IE10. Browser support for each button is noted in the documentation.

    What should be happening is that in legacy browsers the Flash version will be used as a fallback (although note, we'll be dropping support for that in the next major update of Buttons since browser's are actively trying to kill it now). But what seems to be happening is that pdfmake (the library we use for PDF generation) is throwing an error in IE9, rather than featuring detecting and just doing nothing in legacy browsers.

    Try loading your page without pdfmake and the Flash buttons should appear (assuming you have Flash installed and enabled in IE9).

    Allan

This discussion has been closed.