【问题标题】:jquery datatables : Unable to get property 'fnFilter' of undefined or null referencejquery datatables:无法获取未定义或空引用的属性“fnFilter”
【发布时间】:2015-08-20 07:59:11
【问题描述】:

我在我的应用程序中使用 jquery 数据表。下面是我的 JS。

$(document).ready(function() {
    configureSearchDataTable(); 
    bindSearchEvents();     
});

function bindSearchEvents(){
    $('#searchBtn').bind('click',function(event) {          
        var searchCriteriaDelimiter = "#";                                          
        searchResultsTable.fnFilter($('#Name').val()+searchCriteriaDelimiter+$('#Id').val());
        $('#searchResults').show();                 
    });
}

var searchResultsTable;
function configureSearchDataTable(){    
    searchResultsTable = $("#searchResultsTable").dataTable({
        "bServerSide": true,
        "sAjaxSource": "allSearchAjaxResults.form",
        "bProcessing": false,       
        "sPaginationType": "full_numbers",
        "oLanguage": {"sEmptyTable": "No data available", "sLengthMenu" :" _MENU_ items per page",
        "sInfo": "Showing _START_ to _END_ of _TOTAL_ records",
        "sInfoEmpty": "No entries to show"},
        "sDom": 'tlip',
        "aoColumns": [{ "bVisible": false },null,null,null,{ "bVisible": false }]
    });
}

它在页面加载时给出错误“无法获取未定义或空引用的属性'fnFilter'”。不知道这里出了什么问题。

谢谢

【问题讨论】:

  • 你能在命令 "searchResultsTable = $("#searchResultsTable").dataTable({..."
  • 在 configureSearchDataTable() 函数之前出现错误。我在页面加载时的 bindSearchEvents() 函数中的“searchResultsTable.fnFilter($(...”) 行中出现错误。

标签: jquery datatable datatables


【解决方案1】:

正如你所说,你在调用函数 configureSearchDataTable 之前到达函数 bindSearchEvents 这意味着变量 searchResultsTable 从未初始化(searchResultsTablenull)。尝试null.anything 时,我们会收到错误Unable to get property 'anything'

我猜你有另一个地方调用函数bindSearchEvents 在函数中放置断点并检查它从哪里调用。

【讨论】:

  • 感谢您的回复 :).. 我找到了根本原因。我在表-searchResultsTable 中只有三个标题。尽管我已经使第一列数据不显示,但它仍然希望为此定义标题。在表格中添加标题就可以了。
猜你喜欢
  • 1970-01-01
  • 2014-08-01
  • 2020-04-28
  • 2016-08-16
  • 2017-05-18
  • 1970-01-01
  • 2014-08-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多