未捕获的TypeError:$ .fn.DataTable.isDataTable不是函数 [英] Uncaught TypeError: $.fn.DataTable.isDataTable is not a function

查看:378
本文介绍了未捕获的TypeError:$ .fn.DataTable.isDataTable不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据表显示数据库中的数据,并且可以执行删除和编辑操作.使用以下代码,我可以从数据库中获取数据并执行编辑和删除操作.但问题是当我删除特定行时,它已从数据库中删除,但仍显示在数据表中.我使用了"table.destroy();",但是它给出了以下错误. 未捕获的TypeError:$ .fn.DataTable.isDataTable不是函数.

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. 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. Uncaught TypeError: $.fn.DataTable.isDataTable is not a function.

数据表代码:

<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>

推荐答案

对于您的问题,由于在初始化表时设置了table = $('#sun_project_table').DataTable({...});,因此,如果要在销毁表之前检查表是否存在,则可以只需

For your question, since you set 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();
   ...
}

但是我也同意其他评论,如果您只想刷新表,则可以删除该行,或者清除表并通过ajax再次获取它.

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.

这篇关于未捕获的TypeError:$ .fn.DataTable.isDataTable不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆