抱歉我的英语不好 我在初始化代码中遇到了数据表jquery插件的问题。
我进行ajax调用以重新加载并更新网格中的过滤数据,插件通过双初始化返回错误
这是代码
cargarInmuebles(p);
var tablegrid = null;
function cargarInmuebles(params)
{
jQuery(document).ready(function($) {
$.ajax({
url: "getXmlInmuebles.php"+params
}).done(function(data) {
$('marker',data).each(function() {
//code reduced... all variables having data
var itemMarker = ['<img width="141" src="'+imagen+'" height="100" alt="'+idinmueble+'"/>',operacion,dorm,superficie,precio];
markersArray.push(itemMarker);
//here markersArray is correct
});
//here is problem
if(tablegrid)
{
tablegrid.fnDestroy();
tablegrid = $('#grid-basic').dataTable({
"data" : markersArray,
"columns": [
{ "title": "Imagen" },
{ "title": "detalles" },
{ "title": "dorm" },
{ "title": "m2", "class": "center" },
{ "title": "precio", "class": "center" }
]
});
}
else
{
//twice initialization
tablegrid = $('#grid-basic').dataTable({
"data" : markersArray,
"columns": [
{ "title": "Imagen" },
{ "title": "detalles" },
{ "title": "dorm" },
{ "title": "m2", "class": "center" },
{ "title": "precio", "class": "center" }
]
});
}
});
});
}
谢谢。
编辑: 最后它可以在第一次初始化后添加它。
tablegrid = jQuery('#grid-basic')。dataTable({ “bDestroy”:是的 })fnDestroy();
答案 0 :(得分:0)
可能是,您需要替换:
"getXmlInmuebles.php"+params
使用:
"getXmlInmuebles.php?"+params
忘记了?
?
答案 1 :(得分:0)
试试这个:
我建议您使用tablegrid
而不是false
初始化null
,如下所示:
var tablegrid=false;
//Other codes
if(!tablegrid)//check not condition first
{
tablegrid = $('#grid-basic').dataTable({
"data" : markersArray,
"columns": [
{ "title": "Imagen" },
{ "title": "detalles" },
{ "title": "dorm" },
{ "title": "m2", "class": "center" },
{ "title": "precio", "class": "center" }
]
});
}
else
{
tablegrid = $('#grid-basic').dataTable({
"destroy":true, //Try destroying here
"data" : markersArray,
"columns": [
{ "title": "Imagen" },
{ "title": "detalles" },
{ "title": "dorm" },
{ "title": "m2", "class": "center" },
{ "title": "precio", "class": "center" }
]
});
}