Monday, February 20, 2017

All the libraries needed for browser compatible excel export are in following cdn:

https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.js?1=0

So If we have table, which needs to be exported, we can add following script:

<table id="example" class="display nowrap" cellspacing="0" 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>
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
        <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>
        </tbody>
</table>

<script>
$('#example').DataTable( {
        dom: 'Bfrtip',
  "bPaginate": false,
  "ordering": false,
  searching: false,
  bFilter: false,
  "info":     false,
        buttons: [
   {extend:'excel',className:'ButtonSubmit',text:'<i class="fa fa-file-excel-o"></i> Excel'},
            {extend:'copy',className:'ButtonSubmit',text: '<i class="fa fa-files-o"></i> Copy'},
   {extend:'csv',className:'ButtonSubmit',text: '<i class="fa fa-file-text-o"></i> CSV'},
   {extend:'pdf',className:'ButtonSubmit',text: '<i class="fa fa-file-pdf-o"></i> PDF'},
   {extend:'print',className:'ButtonSubmit',text: '<i class="fa fa-print"></i> Print'}
        ]
    } );
</script>

0 comments:

Post a Comment

Powered by Blogger.

Followers

Best Price Amazon Portal

Amazon Best Offers