2

Using the initialization guide from Datatables.net, no matter what changes I've tried the page is returned empty. I've tried hosting the files rather than using the CDN, updating to the most recent versions of jQuery, and searching for this but haven't seen anyone else with this error.

<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.css">

<!-- Initialising DataTables -->
<?
$(document).ready(function(){
$('#tableDataset').DataTable();
});
?>

<table id="tableDataset" class="display">
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Row 1 Data 1</td>
            <td>Row 1 Data 2</td>
        </tr>
        <tr>
            <td>Row 2 Data 1</td>
            <td>Row 2 Data 2</td>
        </tr>
    </tbody>
</table>

<!-- jQuery -->
   <script src="/assets/plugins/dashboard/jquery-1.10.2.min.js" type="text/javascript"></script>

<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.js"></script>
2
  • 1
    your code seems to work perfectly : jsfiddle.net/nr71raL7 Commented Sep 25, 2015 at 21:12
  • I get a 500 error when I include the <!-- Initialising DataTables --> php Commented Sep 25, 2015 at 21:15

2 Answers 2

2

You have wrapped the jQuery onready function inside php open-end tags. Try changing it to the proper tag <script></script>. Also, if you load your javascript files at the bottom of the page, you have to append your functions after them.

Changing your current code to this one solves the problem (jsFiddle):

<!-- jQuery -->
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.js"></script>

<!-- Initialising DataTables -->
<script type="text/javascript">
    $(document).ready(function(){
        $('#tableDataset').DataTable();
    });
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @kmsdev! That's where the issue was created.
0

Change your code to this and try again

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.css">
        <script src="/assets/plugins/dashboard/jquery-1.10.2.min.js" type="text/javascript"></script>
        <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.js"></script>
    </head>
    <body>
       <table id="tableDataset" class="display">
           <thead>
               <tr>
                   <th>Column 1</th>
                   <th>Column 2</th>
               </tr>
           </thead>
           <tbody>
               <tr>
                   <td>Row 1 Data 1</td>
                   <td>Row 1 Data 2</td>
               </tr>
               <tr>
                   <td>Row 2 Data 1</td>
                   <td>Row 2 Data 2</td>
               </tr>
           </tbody>
       </table>

        <script type="text/javascript">
            $(document).ready(function()
            {
                $('#tableDataset').DataTable();
            });
        </script>

    </body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.