Can't get buttons to show up

Can't get buttons to show up

khantashakhantasha Posts: 3Questions: 1Answers: 0
edited February 2016 in Free community support

New(ish) to code and I'm trying my hand at getting datatables to work. I'm linking out to the CDNs, but I can't figure out how to get the little green buttons to show up, and the table doesn't seems to be responsive. What am I doing wrong? Here's my code:

<html>
<head>
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.3/css/jquery.dataTables.css">
<!-- jQuery -->
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://cdn.datatables.net/1.10.3/js/jquery.dataTables.min.js"></script>
 
 
<script type="text/javascript">
$(document).ready(function() {
    $('#example').DataTable();
} );
</script>
 
</head>
 
<body>
<table id="example" class="display" 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>
            
                <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>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</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>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</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>Garrett Winters</td>
                <td>Accountant</td>
                <td>Tokyo</td>
                <td>63</td>
                <td>2011/07/25</td>
                <td>$170,750</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>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>
    </table>
</body>
</html>

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • mmontoyammontoya Posts: 84Questions: 27Answers: 4

    not sure which 'green buttons', but there are a few things you need:
    1) in the <head> section, references to jquery, datatables css files and datatable js files
    2) your $(document).ready should be inside
    3) your data needs to be in html table format.

    the code below has buttons in it as well, but should give you some guidance.


    <!DOCTYPE html> <head> <script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script> <link href="//cdn.datatables.net/1.10.8/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/buttons/1.1.1/css/buttons.dataTables.min.css"> <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/select/1.1.0/css/select.dataTables.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/s/dt/jszip-2.5.0,pdfmake-0.1.18,dt-1.10.10,b-1.1.0,b-colvis-1.1.0,b-flash-1.1.0,b-html5-1.1.0,b-print-1.1.0/datatables.min.css"/> <script src="//cdn.datatables.net/1.10.8/js/jquery.dataTables.min.js"></script> <script type="text/javascript" language="javascript" src="//cdn.datatables.net/buttons/1.1.1/js/dataTables.buttons.min.js"></script> <script type="text/javascript" language="javascript" src="//cdn.datatables.net/select/1.1.0/js/dataTables.select.min.js"></script> <script type="text/javascript" src="https://cdn.datatables.net/s/dt/jszip-2.5.0,pdfmake-0.1.18,dt-1.10.10,b-1.1.0,b-colvis-1.1.0,b-flash-1.1.0,b-html5-1.1.0,b-print-1.1.0/datatables.min.js"></script> <script> $(document).ready(function() { $('#example').DataTable( { searching: false, dom: 'Bfrtip', buttons: [ 'copy', 'excel', 'pdf' ] } ); } ); </script> </head> <body> <table id="example" class="display" 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> </body> </html>
  • mmontoyammontoya Posts: 84Questions: 27Answers: 4

    oops, ignore that very first <br> at the very beginning of my code. also, in this one I turned off that search text box (line 21 in the code above), you probably want to delete that line.

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    Agreed - could you clarify what you mean by the little green buttons? Are you wanting to use Responsive?

    Allan

  • khantashakhantasha Posts: 3Questions: 1Answers: 0

    Thanks mmontoya and allan for answering!

    Yes, Allan, I want it to be responsive, so when you shrink it down the green plus buttons show up that you click and the information that was in rows (when in full screen) drops down below it--just like the table datatables gives in the example on their homepage http://datatables.net/

    How might I get that responsive aspect to show up? Thanks.

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    You need to include the Responsive plug-in that I linked to and enable it using responsive (see the examples in the Responsive documentation). You can include Responsive using the download builder.

    Allan

  • khantashakhantasha Posts: 3Questions: 1Answers: 0

    Thanks! That worked! Voila! :)

This discussion has been closed.