您好,我在同一页面的两个表中使用 Picnet 表过滤器。 其中之一是在我的 js 文件上动态生成的,使用 AJAX 从 MySQL 数据库中检索数据。 另一个具有硬编码数据。
动态生成的那个不行。 (我创建了硬编码的只是为了看看问题是否与此有关) 一开始我还在我的 js 函数中生成了“thead”和“th”标签,但是当我收到一条错误消息说“thead”未定义时,我将该代码移到了 HTML 文件中......目前我只是添加通过附加功能将“tr”和“td”添加到“tbody”...但是过滤器不起作用。对于组合框筛选器,唯一的选项是“选择...”,其他应根据列数据生成的选项则不是。
您知道这里可能存在什么问题吗? 提前致谢...莫妮卡
HTML代码:
<table id="tablaReservas" border="1">
<thead>
<tr><th>Reserva#</th><th filter-type="ddl">Recurso</th><th>Inicio</th><th>Fin</th>th>Responsable</th><th>Usuario</th></tr>
</thead>
<tbody>
</tbody>
</table>
Quick Find: <input type="text" id="quickfind"/><a id="cleanfilters" href="#">Clear Filters</a>
<table id='demotable'>
<thead>
<tr><th filter-type="ddl">Col1</th><th>Col2</th><th>Col3</th></tr>
</thead>
<tbody>
<tr><td>Value 1</td><td>Value 2</td><td>Value 3</td></tr>
<tr><td>Value 4</td><td>Value 6</td><td>Value 8</td></tr>
<tr><td>Value 5</td><td>Value 7</td><td>Value 9</td></tr>
</tbody>
</table>
Javascript 代码:
$(document).ready(inicializar);
function inicializar(){
traerReservas();
var options = { additionalFilterTriggers: [$('#quickfind')], clearFiltersControls: [$('#cleanfilters')]};
$("#tablaReservas").tableFilter(options);
$("#demotable").tableFilter(options);
}
function traerReservas(){
$.ajax({async:true,
url:"../Persistencia/procesaConsultaReservas.php",
type:"POST",
datatype:"json",
success:mostrarTabla,
error:mensajeTablaReservas,
});
}
function mostrarTabla(data){
var d= eval('(' + data + ')');
if (data!=0) {
for (i=0; i < d.length; i++) {
var tr= $("<tr id='" + d[i].id + "' onclick=mostrarRecursos(" + d[i].id + ");>" +
"<td>" + d[i].id + "</td>" +
"<td>" + d[i].nombre + "</td>" +
"<td>" + d[i].inicio + "</td>" +
"<td>" + d[i].fin + "</td>" +
"<td>" + d[i].responsable + "</td>" +
"<td>" + d[i].usuario + "</td>" +
"</tr>");
$("#tablaReservas tbody").append(tr);
}
}
}
最佳答案
初始化document.ready中的PicNet表:
$(document).ready(function() {
$('#m-stats-table').tableFilter();
});
然后,在 ajax 语句的成功回调中,刷新过滤器:
$('#m-stats-table').tableFilterRefresh();
此外,请确保在加载表格之前清除表格时,您没有删除初始的 picnet 过滤器。
这应该有效。
关于javascript - picnet 表过滤器不适用于动态表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7933405/