简体   繁体   English

使用 sorttable - JavaScript 库 - 对 HTML 表进行排序

[英]Using sorttable - JavaScript Library - to Sort HTML Table

I created a table in html for which I need each column to be sorted alphabetically when clicked on the headers.我在 html 中创建了一个表,我需要在单击标题时按字母顺序对每一列进行排序。 I found a suggestion to add the sorrtable.js library and add the class name sortable to the table.我找到了添加 sorrtable.js 库并将 class 名称可排序到表中的建议。 When I run the html page directly on PyCharm, it does the sorting successfully, but when I run the web app as a whole, the headers do not allow sorting.当我直接在 PyCharm 上运行 html 页面时,它会成功排序,但是当我运行 web 应用程序作为一个整体时,标题不允许排序。 In essence, clicking the headers does nothing.本质上,单击标题什么都不做。 I don't understand what could be causing this.我不明白是什么原因造成的。 Any help would be greatly appreciated!!任何帮助将不胜感激!!

My HTML Code:我的 HTML 代码:

<script src="sorttable.js"> </script>

{% block content %}

<div class="container">
    <div class="row">
        <div class="col md-12">

            <div style="width:1110px; margin-top: 40px" class="jumbotron p-3">

                <table class="sortable table table-hover table-striped">

                    <thead>
                    <tr>
                            <th>Guidance Tracker</th>
                            <th>Department</th>
                            <th>Agency</th>
                            <th>Funding Source</th>
                    </tr>
                    </thead>

                    <tbody>
                    <tr>
                        <td>KJ</td>
                        <td>Department of Health and Human Services</td>
                        <td>Health Resources</td>
                        <td><a href="/Department">PPP-Rural Health</a></td>

                    </tr>

                    <tr>
                        <td>Lauren</td>
                        <td>Department of Treasury</td>
                        <td>Internal Revenue Service</td>
                        <td><a href="/Department">2021 Recovery Rebates</a></td>
                    </tr>

                    <tr>
                        <td>Liam</td>
                        <td>Department of Agriculture</td>
                        <td>Department of Agriculture</td>
                        <td><a href="/Department">CARES-Food Assistance</a></td>
                    </tr>

                    <tr>
                        <td>Jackson</td>
                        <td>Department of Justice</td>
                        <td>Office of Justice Programs</td>
                        <td><a href="/Department">CARES-Supplemental Funding</a></td>
                    </tr>
                </tbody>
               </table>


        </div>
      </div>
    </div>
</div>

{% endblock content %}

Do you load your sorttable.js file correctly?您是否正确加载了 sorttable.js 文件? I made below snippet by just copy-paste your table structur and just load the sorttable js differently.我通过复制粘贴您的表格结构并以不同方式加载 sorttable js 制作了以下片段。 everything looks ok.一切看起来都很好。 doesn't it?不是吗?

 table,tr,td,th { border: 1px solid #000; border-collapse: collapse; padding: 10px }
 <script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script> <div class="container"> <div class="row"> <div class="col md-12"> <div style="width:1110px; margin-top: 40px" class="jumbotron p-3"> <table class="sortable table table-hover table-striped" id='test'> <thead> <tr> <th>Guidance Tracker</th> <th>Department</th> <th>Agency</th> <th>Funding Source</th> </tr> </thead> <tbody> <tr> <td>KJ</td> <td>Department of Health and Human Services</td> <td>Health Resources</td> <td><a href="/Department">PPP-Rural Health</a></td> </tr> <tr> <td>Lauren</td> <td>Department of Treasury</td> <td>Internal Revenue Service</td> <td><a href="/Department">2021 Recovery Rebates</a></td> </tr> <tr> <td>Liam</td> <td>Department of Agriculture</td> <td>Department of Agriculture</td> <td><a href="/Department">CARES-Food Assistance</a></td> </tr> <tr> <td>Jackson</td> <td>Department of Justice</td> <td>Office of Justice Programs</td> <td><a href="/Department">CARES-Supplemental Funding</a></td> </tr> </tbody> </table> </div> </div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM