jquery - 使用数据表 jquery 进行烧瓶表搜索
问题描述
我正在开发一个 Flask 应用程序,它处理数据并生成一个 pandas 数据框,然后我将其显示在一个 HTML 页面上,我在该页面上应用如下条件格式,
<div style="margin-top:1%;margin-left:6%;margin-right:6%;max-height: 500px,max-width: 150px">
<table id="myTable" class="table table-fixed">
<thead>
<tr>
{% for header in headers %}<th>{{ header }} </th>{% endfor %}
</tr>
</thead>
{% for i in data_index_len %}
<tr>
{% for j in headers %}
{% if j in SLA_Status %}
{% if math.isnan(data.ix[i,j]) %}
<td><b>{{ data.ix[i,j] }}</b></td>
{% elif data.ix[i,j] < target[i] %}
<td bgcolor="#f1948a"><b>{{ data.ix[i,j] }}</b></td>
{% elif data.ix[i,j] >= target[i] %}
<td bgcolor="#31e960"><b>{{ data.ix[i,j] }}</b></td>
{% else %}
<td bgcolor=" #cacfd2"><b>{{ data.ix[i,j] }}</b></td>
{% endif %}
{% else %}
<td>{{ data.ix[i,j] }}</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>
</div>
我现在想应用数据表 jquery 进行表搜索,我使用的 js 如下:
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#myTable tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#myTable').DataTable();
// Apply the search
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );} );
由于某些原因,搜索在表格上不起作用,但排序元素处于活动状态,请求专家帮助
解决方案
数据表插件和下面的脚本对我有用,谢谢
<script>
$(document).ready(function() {
$('#myTable').DataTable();
} );
</script>
推荐阅读
- javascript - 如何在 php 的 restful api 中嵌入 Javascript 函数?
- python - 合并列和行
- javascript - 组件不会渲染
- javascript - 单击按钮后如何在谷歌表格侧边栏中打开网页
- protractor - VSTS 构建失败并显示“失败:ETIMEDOUT 连接 ETIMEDOUT 66.85.49.22:443”
- c# - WPF MVVM 绑定 Windows 页面中不同 UserControls 的列表
- mysql - MySQL 性能 - 视图 v/s 加入索引表
- c++ - 如何简洁地将一个数组的范围分配给另一个数组的范围?
- angular - Ionic 3 - 以格式化方式显示来自 HTTP 请求的 JSON 响应
- java - Chrome CustomTabs CustomTabsCallback onPostMessage 未调用