Làm thế nào để khởi tạo lại một jQuery datatable? Tôi thậm chí đã cố gắng loại bỏ phần tử bảng. Vẫn bảng đó đang hiển thị. Mã của tôi giống như sau:Cách khởi động lại jquery Có thể định cấu hình
function removeExistingDataTableReference(tableid)
{
if(oTable !=null)
{
oTable.fnDestroy();
}
if(document.getElementById(tableid)){
document.getElementById(tableid).innerHTML="";
}
oTable=null;
try
{
if(oTable !=null)
{
//oTable.fnDestroy();
alert("error in fndestroy");
}
oTable=null;
if(document.getElementById(tableid)){
document.getElementById(tableid).innerHTML="";
}
if(document.getElementById("FTable"))
{
removeElement(document.getElementById("FTable"));
}
}
catch(e)
{
alert("Error happend:"+e.message);
}
}
function removeElement(element)
{
try
{
var elem = document.getElementById('FTable');
elem.parentNode.removeChild(elem);
//ert(element.parentNode.id);
//element.parentNode.removeChild(element);
alert("removed");
return true;
}
catch(e)
{
alert(e.message);
}
return false;
}
Tôi làm như thế nào? Sau khi bảng bấm nút tìm kiếm được tải. Một lần nữa, khi tôi tìm kiếm với thông số tìm kiếm khác, bảng sẽ tải với dữ liệu mới. Điều đó không xảy ra. Làm thế nào để sửa chữa nó ??
Bảng được khởi tạo như thế này:
function createDataTable()
{
try
{
oTable = $('#FTable').dataTable({
"bDestroy":true,
"bJQueryUI": true,
"sScrollX": "100%",
"sScrollXInner": tablewidth+"px",
"bScrollCollapse": true,
"bSort":false,
"iDisplayLength" : 50,
"sPaginationType" : "full_numbers",
"aLengthMenu": [[10, 18, 50, -1], [10, 18, 50, "All"]]
});
new FixedColumns(oTable, {
"iLeftColumns": 1,
"iRightColumns": 1
});
}
catch (e)
{
alert(e.message);
}
}
tôi không sử dụng fnAddData.Each khi tôi tạo ra một bảng html động sau đó tôi chuyển nó sang DataTable (tức là bằng cách gọi createDataTable() chức năng) – vmb
Bạn đang tạo bảng động như thế nào? Bạn không thể có hai thể hiện của datatable trên cùng một bảng. Bạn có thể tạo bảng động bằng cách sử dụng fnAddData quá và đây là cách chính xác AFAIK – dejavu
đầu tiên tôi sẽ tạo bảng html bằng cách thêm td và tr động .... sau đó tôi sẽ gọi chức năng khởi tạo – vmb