user1552172
user1552172

Reputation: 676

Datatables Jquery error in console

Uncaught TypeError: Object [object Object] has no method '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' I am not sure why this is happening the jquery is included because the datatable is being created just fine. Any help on this will be great.

Upvotes: 0

Views: 1844

Answers (2)

Barbara Laird
Barbara Laird

Reputation: 12717

You need to get the dataTable object, instead of the jQuery object.

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

From the docs:

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

  // Sometime later - filter...
  oTable.fnFilter( 'test string' );
} );

Upvotes: 2

Mamuz
Mamuz

Reputation: 1730

You have to chain with dataTable object, like this..

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

Upvotes: 3

Related Questions