jquery datatables:columnFilter()不是函数错误 [英] jquery datatables: columnFilter() is not a function error

查看:407
本文介绍了jquery datatables:columnFilter()不是函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用数据表与自定义服务器端过滤,搜索和排序...为什么columnFilter()返回错误TypeError:$(...)。DataTable(...)。columnFilter不是函数

i am using Data Tables with custom server side filtering, search and sorting... why is the columnFilter() returning an error "TypeError: $(...).DataTable(...).columnFilter is not a function"

这里是我如何使用columnFilter:

here is how i use columnFilter:

var table = $('#item-table').DataTable({
    ajax: '<?= site_url("price_update"); ?>',
    serverSide: true,
    processing: true,
    paging: true
}).columnFilter();

我的代码没有.columnFilter()工作正常。

my code without the ".columnFilter()" works fine.

推荐答案

必须使用oldschool dataTable() columnFilter 。概念证明:

You must use the "oldschool" dataTable() constructor when using columnFilter. Proof of concept :

不工作,产生与问题相同的错误:

columnFilter与1.10.x实例化与 DataTable() - > http://jsfiddle.net/87kam74q/

works not, produces same error as in the question :
columnFilter with 1.10.x instantiated with DataTable() -> http://jsfiddle.net/87kam74q/

工作

columnFilter与1.10.x实例化为 dataTable() - > http://jsfiddle.net/LvL4vm8e

works :
columnFilter with 1.10.x instantiated with dataTable() -> http://jsfiddle.net/LvL4vm8e/

原因是, columnFilter 假定它正在使用旧jQuery对象,而不是新的API对象。虽然,您仍然可以通过 .api()方法访问新的API,例如:

The reason is, that columnFilter assumes it is working the "old" jQuery object, not the new API object. Though, you can still access the new API through the .api() method, for example :

var table = $('#example').dataTable();
table.api().search('test').draw();






如果您不想通过 table.api()使用新的AP,并坚持使用 DataTable(),您可以通过放弃实现相同链接:


If you not want to go through table.api() for using the new AP, and insists on using DataTable(), you can achieve the same by giving up the chaining :

var table = $('#example').DataTable();
$('#example').dataTable().columnFilter({
    sPlaceHolder : 'head:before',
    aoColumns: [ { type: "text"},
                 { type: "text"},
                 { type: "text"},
                 { type: "text"},
                 { type: "text"}
               ] 
});

小提琴 - > http://jsfiddle.net/qbr01oya/ 。这不会导致dataTable被初始化两次(dataTables检查)。

fiddle -> http://jsfiddle.net/qbr01oya/. This does not result in the dataTable being initialized twice (dataTables check for that).

这篇关于jquery datatables:columnFilter()不是函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆