Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Jquery Datatable not working with html table

juggin95

New Coder
Hi all,

I'm having an issue where im trying to convert a html table to a DataTable using Jquery, however I am seeing NO change.

I've added the links so that JQuery is first, datatables.css is second, then datables.js is third.

I got the 2 Datatable links from:

And I for the JQuery CDN from:

See code below. I'm not sure what i'm doing wrong!

Many thanks for any insights

Code:
<head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.css">
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.js"></script>
</head>

<body>
<div class="container">
    <h1>Product Table</h1>
    <table class='table table-bordered' id="product_table">
        <thead>
            <tr>
                <th>Product ID</th>
                <th>Product Name</th>
                <th>KG</th>
                <th>Length</th>
                <th>Width</th>
                <th>Height</th>
                <th>Price (£)</th>
            </tr>
        </thead>
        {% for product in products %}
        <tr>
            <td>{{product.product_id}}</td>
            <td>{{product.product_name}}</td>
            <td>{{product.kg}}</td>
            <td>{{product.length}}</td>
            <td>{{product.width}}</td>
            <td>{{product.height}}</td>
            <td>{{product.price}}</td>
        </tr>
        {% endfor %}
    </table>
</div><!--End of display table-->
</body>
{% endblock %}

<script type="text/javascript">
    $(document).ready(function(){
        $('#product_table').DataTable();
    });
</script>
</html>
 
Last edited:

New Threads

Buy us a coffee!

Back
Top Bottom