简体   繁体   English

未捕获的TypeError:$ .fn.DataTable.isDataTable不是函数

[英]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.

相关问题 未捕获的TypeError:$ .fn.maze不是函数 - Uncaught TypeError: $.fn.maze is not a function Vue Uncaught TypeError:fn.bind不是函数 - Vue Uncaught TypeError: fn.bind is not a function 未捕获的TypeError:fn在chart.js中不是函数 - Uncaught TypeError: fn is not a function in chart.js 未捕获的类型错误:fn.call 不是函数 - Uncaught TypeError: fn.call is not a function 未捕获的TypeError:对象[对象DOMWindow]的属性&#39;fn&#39;不是函数 - Uncaught TypeError: Property 'fn' of object [object DOMWindow] is not a function 错误消息“Uncaught TypeError: undefined is not a function”(数据表) - Error message "Uncaught TypeError: undefined is not a function" (DataTable) 为什么我得到 Uncaught TypeError: $(...).DataTable is not a function - Why I get Uncaught TypeError: $(…).DataTable is not a function 无法读取未定义/未捕获类型错误的属性“fn”:$(...).daterangepicker 不是函数 - Cannot read property 'fn' of undefined / Uncaught TypeError: $(...).daterangepicker is not a function 未捕获的TypeError:$ .fn.snd_slider.external_move_to不是函数 - Uncaught TypeError: $.fn.snd_slider.external_move_to is not a function jquery 错误:未捕获的类型错误:$(…).DataTable 不是 function - jquery error: Uncaught TypeError: $(…).DataTable is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM