Grizzly
Grizzly

Reputation: 5943

jQuery Datatables buttons showing as links.. not buttons

Using jQuery DataTables 1.10.15 and I am trying to use the file export options.

Here is how my scripts are loaded on the page:

<script src="/Scripts/DataTables/jquery.dataTables.js"></script>
<script src="/Scripts/DataTables/dataTables.bootstrap.js"></script>
<script src="/Scripts/DataTables/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.print.min.js"></script>

Here is my DataTable setup:

var table = $('#NewTable').DataTable({
    dom: 'Bfrtip',
    buttons: [ 'excel', 'pdf' ],
    'aoColumnDefs': [
        { "bSortable": false, "aTargets": [2, 7] },
        { "bSearchable": false, "aTargets": [7] }
    ]
});

Here is how they appear:

enter image description here

How do I get them to appear as buttons and not links?

Upvotes: 0

Views: 875

Answers (1)

H77
H77

Reputation: 5967

You're most likely missing the proper css file.

Try adding this css link (from CDN) to your header.

https://cdn.datatables.net/buttons/1.3.1/css/buttons.dataTables.min.css

Working example:

var table = $('#NewTable').DataTable({
    dom: 'Bfrtip',
    buttons: [ 'excel', 'pdf' ],
    'aoColumnDefs': [
        { "bSortable": false, "aTargets": [2, 7] },
        { "bSearchable": false, "aTargets": [7] }
    ]
});
<link href="https://cdn.datatables.net/buttons/1.3.1/css/buttons.dataTables.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.3.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.print.min.js"></script>
<table id="NewTable"></table>

Upvotes: 2

Related Questions