问题
I'm attempting to use a custom input for searching/filtering a jQuery Datatables table. I'm using jQUery 2.1.1 and DataTables 1.10.4. My code is pretty simple, and mirrors what's in the API docs:
var table = $('#pList').DataTable({
"pageLength": 25,
"lengthChange": false,
"ajax": 'partsJSON.cfm'
});
$('#pdb-filter').on( 'keyup', function () {
console.log(table);
table.search( this.value ).draw();
} );
When I run the page and make entries in the input, I get the following in the console:
TypeError: table.search(...).draw is not a function
Followed by:
Object { context: Array[1], selector: Object, tables: O/q.extend/h/<(), table: O/q.extend/h/<(), draw: O/q.extend/h/<(), page: O/q.extend/h/<(), ajax: Object, rows: O/q.extend/h/<(), row: O/q.extend/h/<(), columns: O/q.extend/h/<(), 14 more… }
My reading of that says that "draw" is the fifth element in the table object.
Additionally, when I type the code into the console manually, (without the init options, of course) everything works fine. I get no errors.
Anybody got any ideas?'
来源:https://stackoverflow.com/questions/27067590/datatables-typeerror-draw-is-not-a-function