【问题标题】:Unable to customize tables with jquery-datatables to sort/filter/order at display side无法使用 jquery-datatables 自定义表以在显示端进行排序/过滤/排序
【发布时间】:2019-05-28 05:06:47
【问题描述】:

我有一个 html 文件来使用烧瓶应用程序呈现我的表格。它工作正常,我想使用数据表添加一些自定义。

我真的不确定要在 jQuery 部分的哪个位置添加自定义项。我的代码在 html 文件中有它,但是当我运行它时我没有看到自定义工作。它应该是我的项目文件夹中的 static/js/jquery.js 文件吗?我下载了数据表,但我没有看到结果。

<!DOCTYPE html>
<html>
<head>

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

src="https://code.jquery.com/jquery-1.11.1.min.js"></script> // 
JQuery Reference

<script

src="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js">    
</script>
<script

src="https://cdn.datatables.net/plug- 
 ins/9dcbecd42ad/integration/jqueryui/dataTables.jqueryui.js">
</script>
<link rel="stylesheet"

href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery- 
 ui.css">
 <link rel="stylesheet"

 href="https://cdn.datatables.net/plugins/9dcbecd42ad/integration/
  jqueryui/dataTables.jqueryui.css">

  <style type="text/css">
body {
  background: seashell;
  color: black;
}
div.container {
  max-width: 500px;
  margin: 100px auto;
  border: 20px solid white;
  padding: 10px;
  text-align: center;
}
h4 {
  text-transform: uppercase;
}
  </style>
  <title>{{ title }} - Queues</title>
</head>
  <body>
    <h2>Page for Queues display </h2>
    <p style="color:blue;">Queues information</p>
    <table border="1">
      <th style="text-align:left;">Job</th>
  <th style="text-align:left;">Team</th>
  <th style="text-align:left;">Problem</th>
  <th style="text-align:left;">CPU</th>
  <th style="text-align:left;">Memory</th>
  {% for row in data%}
  <tr>
    <td>{{ row[0] }}</td> <td>{{ row[1] }}</td> <td>{{ row[2] }}</td> <td>{{ row[3] }}</td> <td>{{ row[4] }}</td>
  </tr>
  {% endfor %}
</table>

我得到了正确显示数据但没有自定义的表格。我按照本示例中的说明进行操作:https://www.codeproject.com/Tips/844403/%2FTips%2F844403%2FjQuery-Datatables-For-Beginners

【问题讨论】:

    标签: python html datatables flask-appbuilder


    【解决方案1】:

    我过去发现,在使用数据表时,如果您的表中不包含&lt;tbody&gt;&lt;thead&gt; 标记,则该表将不会显示为数据表。这些显示在您发送的链接中,但不在您的代码中。

    【讨论】:

    • 谢谢,我改了!虽然它看起来像一张普通的桌子。我想知道如何识别这是否是一个数据表。
    • 似乎有一个初始化代码$(document).ready(function() { $('#example').dataTable(); } ); 我将其添加为.js 文件,但我没有看到启用数据表的功能。
    • 您需要将用于初始化它的 id 添加到表中。因此,在这种情况下,您的表的 id 应该是 example。所以&lt;table id="example" border="1"&gt;
    猜你喜欢
    • 2014-01-05
    • 2013-12-15
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 2013-04-09
    • 2020-12-09
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多