[Django] django + able is simple to use in tables, djangodatatable

Source: Internet
Author: User

[Django] django + able is simple to use in tables, djangodatatable

To use datatable, you must first download the datatable file. The file mainly includes three folders: css, img, and js. how to configure them in django?

First, you must introduce the datatable file in the template in the following format:

    <!-- DataTables CSS -->    <link rel="stylesheet" href="{% static 'DataTables/css/jquery.dataTables.css' %}">    <!-- jquery -->    <script src="{% static 'js/jquery/jquery.min.js' %}"></script>    <!-- DataTables -->    <script src="{% static 'DataTables/js/jquery.dataTables.js' %}"></script>


Note that the js file in datatables must be referenced after the jquery file.

In django, how does one make data use the Ables table?

The Code is as follows:

     <table id="table_id" class="display">            <thead>                <tr>                    <th>Column 1</th>                    <th>Column 2</th>                </tr>            </thead>            <tbody>            {% for d in data %}                <tr>                    <td>{{ d.col1 }}</td>                    <td>{{ d.col2 }}</td>                </tr>             {% endfor %}            </tbody>        </table><script>
$(document).ready( function () {
                $('#table_id').DataTable();
            } );
</Script>


Finished!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.