【发布时间】:2013-06-24 15:22:15
【问题描述】:
单击按钮时,我有数据表来显示来自服务器的值。这是一种搜索功能。如果更改搜索文本框的值并再次单击,则不会反映更改。
第二次数据表没有显示正确的值。
jQuery("#dialog-form").dialog ({
autoOpen: false,
height: 500,
width: 750,
modal: true,
buttons : {
"Search" : function() {
jQuery.ajax({
url : 'action="part"/>',
data : {"product" : $("#productsTextArea").val()},
dataType : 'json',
success : function(data){
var newarray=[];
while(data.length > 0) {
newarray.push(data.splice(0,2));
}
oTable = $("#products").dataTable({
"aaData" : newarray,
"bProcessing" : true,
"sPaginationType" : "full_numbers",
"bDeferRender": true,
"bJQueryUI" : true,
"bRetrieve" : true,
"bPaginate" : true,
"bSort" : true,
"aaSorting" : [[ 4, "desc" ]],
"iDisplayLength" : 15,
"aoColumnDefs": [
{"fnRender": function(o, val){
return o.aData[0];
},
"sClass":"prod", "aTargets": [ 0 ] },
{"fnRender": function(o, val){
return o.aData[1];
},
"sClass":"Description", "aTargets": [ 1 ] }
]
});
【问题讨论】:
-
从您的描述中很难确定。使用 Datatables,您可以加载包含所有表数据的页面,然后使用数据表搜索框过滤这些行;或者您可以使用 Ajax 源,它会在搜索框中输入每个字符后轮询您的服务器。
-
更新了代码...这将有助于理解我的问题。
-
我看不到您在哪里重新初始化数据表。您可能已通过 ajax 成功取回数据,但您并未更新表。
-
您尝试清除 otable 吗?像 $('#products').empty(); ?
标签: jquery-ui jquery datatables