DataTable不是交互式的

时间:2017-01-09 19:29:54

标签: javascript flask datatables

我正在尝试将一个DataTables对象创建到一个烧瓶应用程序中。格式更改,并添加了搜索栏,但列不可排序,搜索栏不起作用。

编辑:该应用可在以下位置找到: https://eve-pi-profits.herokuapp.com/jita

目前jita页面是我唯一正在处理的页面。一旦我让表格工作,我会将其复制到其他表格。

这是我的html jinja2模板

 {% extends "index.html"%}
 {% block title %}
 <h1>Jita</h1>
{% endblock %}
{% block content %}
     <table id="mainTable" class="table table-striped">
     <thead>
    <tr>
        <th>Name</th>
        <th>Price</th>
        <th>Profit</th>
        <th>Profit Margin</th>
    <th>Datetime</th>
</tr>
</thead>
<tbody>
{% for entry in entries %}
<tr>
    <td>{{entry[0]}}</td>
    <td>{{entry[1]}}</td>
    <td>{{entry[2]}}</td>
    <td>{{entry[3]}}</td>
    <td>{{entry[4]}}</td>
</tr>
</tbody>
{% endfor %}
</table>
{% endblock %}

...
<script src="../static/js/vendor/jquery.dataTables.min.js"></script>

这是我的javascript

$(document).ready(function() {
$('#mainTable').DataTable( {
    "paging":   true,
    "ordering": true,
    "info":     true
    "order": [[4, "asc"]]
} );
} );

编辑:这是我的index.html文件

<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <!         [endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang=""> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="apple-touch-icon" href="apple-touch-icon.png">

        <link rel="stylesheet" href="../static/css/bootstrap.css">
        <style>
        body {
            padding-top: 50px;
            padding-bottom: 20px;
        }
    </style>
    <link rel="stylesheet" href="../static/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="../static/css/main.css">
    <link href="https://fonts.googleapis.com/css?    family=Racing+Sans+One|Righteous|Quicksand" rel="stylesheet">
    <script src="../static/js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
</head>
<body>
    <!--[if lt IE 8]>
        <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="{{url_for('index')}}">EvePIProfits.com</a>
       <div class="btn"><a href="{{url_for('jita')}}">Jita</a></div>
       <div class="btn"><a href="{{url_for('amarr')}}">Amarr</a></div>
       <div class="btn"><a href="{{url_for('rens')}}">Rens</a></div>
       <div class="btn"><a href="{{url_for('dodixie')}}">Dodixie</a></div>
    </div>
    <div id="navbar" class="navbar-collapse collapse">


    </div><!--/.navbar-collapse -->

  </div>
</nav>

<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
  <div class="container">
  {% block title %}
    <h1>EVE PI Profits</h1>
    <p>Planetary interaction profitability across New Eden</p>
  {% endblock %}

      {% block content %}{% endblock %}
  </div>
</div>

<div class="container">
  <!-- Example row of columns -->
  <div class="row">
  <p>
  {{table}}
   </p>
  </div>

  <hr>

  <footer>
    <p>&copy; Wm. Stephen Scott 2017</p>
  </footer>
</div> <!-- /container -->        <script    src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script>

    <script src="../static/js/vendor/bootstrap.min.js"></script>
    <script src="../static/js/vendor/jquery.dataTables.min.js"></script>
    <script src="../static/js/main.js"></script>


    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
    <script>
        (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
        function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
        e=o.createElement(i);r=o.getElementsByTagName(i)[0];
        e.src='//www.google-analytics.com/analytics.js';
        r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
        ga('create','UA-XXXXX-X','auto');ga('send','pageview');
    </script>
</body>
</html>

感谢您的协助。

2 个答案:

答案 0 :(得分:0)

试试这个..

通过

替换你的javascript
$(document).ready(function() {
$('#mainTable').DataTable( {
        "paging":   true,
        "ordering": true,
        "info":     true,
        "sortable":true,
        "aaSorting": [[4, "asc"]]
    } );
} );

答案 1 :(得分:0)

标签位于for循环中。我把结束标签移到了循环外面,然后就可以了。