[英]Uncaught TypeError: $.fn.DataTable.isDataTable is not a function
I am using a data table to display data from database and i can perform delete and edit actions.with below code i am able to fetch data from database and perform edit and delete. 我正在使用数据表显示数据库中的数据,并且可以执行删除和编辑action.with下面的代码,我能够从数据库中获取数据并执行编辑和删除。 but the issue is when i delete particular row it is deleted from database but still it is displayed in data table.
但问题是当我删除特定行时,它已从数据库中删除,但仍显示在数据表中。 i made use of "table.destroy();"but it gives the following error.
我使用了“ table.destroy();”,但是它给出了以下错误。 Uncaught TypeError: $.fn.DataTable.isDataTable is not a function.
未捕获的TypeError:$ .fn.DataTable.isDataTable不是函数。
code for datatable: 数据表代码:
<script>
var table;
if($.fn.DataTable.isDataTable('#sun_project_table') ) {
table=$('#sun_project_table').DataTable();
table.destroy();
//$('#category_table_body').empty();
}
table=$('#sun_project_table').DataTable({
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"iDisplayLength": <?php echo 10; ?>,
'bProcessing' : true,
'bServerSide' : true,
'sAjaxSource' : "<?php echo base_url();?>index.php/Registrationc/displayinfo8",
columns: [
{ "name": "van_village_mapping.van_id", "data": "van_id" },
{ "name": "van_village_mapping.village_id", "data": "village_id" },
{ "name": "Actions", "data": "Actions" }
],
"columnDefs": [
{
}],
"createdRow": function ( row, data, index ) {
},
'fnServerData': function(sSource, aoData, fnCallback)
{
aoData.push();
$.ajax
({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
},
"oTableTools": {
"sSwfPath": "assets/media/swf/copy_csv_xls_pdf.swf",
},
"oLanguage": {
"sSearch": "Filter: "
}
});
});
</script>
<script>
function delete_van_village_mapping($1){
$.ajax({
type:"POST",
url: "<?php echo base_url(); ?>index.php/Registrationc/delete_van_village_mapping1",
data:{van_village_mapping_id:$1},
success: function()
{
alert('done!');
}
});
};
</script>
For your question, since you set table = $('#sun_project_table').DataTable({...});
对于您的问题,由于您设置了
table = $('#sun_project_table').DataTable({...});
when you initialize the table, thus if you want to check if the table exists before you destroy it, you can just do 在初始化表时,因此如果要在销毁表之前检查表是否存在,可以
if(table) {
table.destroy();
...
}
But I agree with other comment, if you just want to refresh the table, you can just remove the row, or clear the table and fetch it again via ajax. 但是我同意其他意见,如果您只想刷新表,则可以删除该行,或者清除表并通过ajax再次获取它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.