0

未捕获的类型错误:对象 [object Object] 没有方法“fnFilter”

$(document).ready(function () {

var selectedColumn = $('#columnlist').find(":selected").text();

$('#csearchtext').bind("change paste keyup", function () {
    var input = $('#csearchtext').val();

    console.log(input);

    $('#table_id').fnFilter('',4);
});

$('#dblist').on('change', function () {

    var selected = $('#dblist').find(":selected").text();
    tablefill(selected);

});

$('#search').click(function () {

    var selected = $('#dblist').find(":selected").text();
    tablefill(selected);

});

function tablefill(selected) {
    $('.advsearchbar').show();
    $('#stable').show();

    $('#table_id').dataTable({
        "sAjaxSource": '/php/connect/searchtablequery.php',
        "bProcessing": true,
        "sScrollY": "500px",
        "bDeferRender": true,
        "bDestroy": true,
        "sAjaxDataProp": "",
        "fnServerParams": function (aoData) {
            aoData.push({ "name": "db", "value": selected });
        },
        "aoColumns": [
            { "mData": "calldate" },
            { "mData": "recordingfile" },
            { "mData": "uniqueid" },
            { "mData": "src" },
            { "mData": "did" },
            { "mData": "lastapp" },
            { "mData": "dst" },
            { "mData": "disposition" },
            { "mData": "duration" },
            { "mData": "userfield" },
            { "mData": "accountcode"}],
        "iDisplayLength": 20,
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "sDom": '<"H"Tfr>t<"F"ip>',
        "oTableTools": {
            "sSwfPath": "/DataTables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf",
            "aButtons": [
                "copy", "csv", "xls", "pdf",
                {
                    "sExtends": "collection",
                    "sButtonText": "Save",
                    "aButtons": ["csv", "xls", "pdf"]
                }]
        }
    });
}

});

Uncaught TypeError: Object [object Object] has no method 'fnFilter' 我不确定为什么会发生这种情况,包含 jquery,因为数据表创建得很好。对此的任何帮助都会很棒。

4

2 回答 2

3

您必须像这样链接 dataTable 对象。

$('#table_id').dataTable().fnFilter('', 4);
于 2013-09-12T21:35:36.913 回答
2

您需要获取 dataTable 对象,而不是 jQuery 对象。

$('#table_id').dataTable().fnFilter('',4);

从文档:

$(document).ready(function() {
  var oTable = $('#example').dataTable();

  // Sometime later - filter...
  oTable.fnFilter( 'test string' );
} );
于 2013-09-12T21:36:15.587 回答