【问题标题】:datatables + adding a filter per column数据表 + 每列添加一个过滤器
【发布时间】:2015-10-20 02:29:40
【问题描述】:

如何让搜索/过滤器按列工作?

我正在构建小步骤,并不断添加到我的数据表中,这在这个阶段非常动态。它基本上基于输入的数据构建数据表。我现在添加了页脚作为搜索/过滤器,但不幸的是,这是我卡住的地方。我无法让文件管理器部分工作。非常感谢您的建议。

这是我正在处理的示例数据表http://live.datatables.net/qociwesi/2/edit

它基本上具有按表构建的 dTableControl 对象。

要构建我的表,我需要调用 loadDataFromSocket 来执行以下操作:

//then I have this function for loading my data and creating my tables
//file is an array of objects
//formatFunc is a function that formats the data in the data table, and is stored in options for passing to the dTableControl for formatting the datatable - not using this in this example
//ch gets the keys from file[0] which will be the channel headers
//then I add the headers
//then I add the footers
//then I create the table
//then i build the rows using the correct values from file
//then I draw and this then draws all the row that were built
//now the tricky part of applying the search to each columns

所以我已经做到了这一点,但每列的搜索不起作用。如何让搜索/过滤器按列工作?

请注意,这是我一直在研究的一个非常基本的工作示例:http://jsfiddle.net/HattrickNZ/t12w3a65/

【问题讨论】:

    标签: filter datatables


    【解决方案1】:

    您应该使用t1.oTable 访问DataTables API,请参阅updated example 进行演示。

    请将您的代码与问题中的 jsFiddle 进行比较,注意其简单性并考虑重写您的代码。

    【讨论】:

    • tks,你能否详细说明我为什么要重写。 jsfiddle 示例是数据表工作的静态表,而我的示例是动态的并且能够绘制给它的内容。这就是为什么它更复杂的原因。您的回复将不胜感激,因为我只是一个新手!
    • @HattrickNZ,虽然您的代码允许您动态构建表格,但我认为您的代码没有必要复杂。这将导致将来的维护出现错误和问题。代码复杂性很可能是您错误使用t1 而不是t1.oTable 的原因。
    • tks 但更具体地说是dTableControl 对象是复杂部分还是构建数据表的loadDataFromSocket 函数?还是它的组合?谢谢你的建议,我会看看如何简化它。
    猜你喜欢
    • 2013-02-16
    • 2021-03-26
    • 2020-11-17
    • 2013-05-14
    • 1970-01-01
    • 2018-11-26
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多