zoukankan      html  css  js  c++  java
  • [django]django+datatable简单运用于表格中

    使用datatable首先需要下载datatable文件,文件主要包括三个文件夹css,img,js相关文件,在django中如何配置呢?

    首先需要在模板中引入datatable文件,格式如下:

        <!-- 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>


    注意datatables中的js文件需要引用在jquery文件之后.

    那么django中如何让数据使用datatables表格呢?

    代码如下:

         <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>


    完毕!

  • 相关阅读:
    10.20stark组件已经完工
    webpack3到webpack4
    app埋点
    postman使用
    phantomjs
    nodejieba中文分词
    爬虫--cheerio
    mysql命令(三)
    mysql学习(二)
    mysql安装登录
  • 原文地址:https://www.cnblogs.com/CQ-LQJ/p/5356982.html
Copyright © 2011-2022 走看看