首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataTables搜索和过滤动态添加的包含输入字段的行

DataTables搜索和过滤动态添加的包含输入字段的行
EN

Stack Overflow用户
提问于 2015-08-25 01:57:23
回答 1查看 2.8K关注 0票数 0

http://jsfiddle.net/v7rjqogy/15/

它有两个地方出了问题。首先:

当我添加一个新行,然后在输入中填入一些文本时,我如何让它与搜索功能一起工作?

其次(这个更重要)

您会注意到,我在页面顶部添加了一个自定义过滤器: Strength:和By page。这些与表中的强度和剂量列相对应。我已经添加了代码来让它按这些进行搜索,但它总是不显示任何返回的行。

代码语言:javascript
复制
$(document).ready(function () {

    $.fn.dataTableExt.ofnSearch["html-input"] = function (value) {
        return $(value).val();
    };

    var table = $("#lines").DataTable({
        "searching": true,
        "ordering": true,
        columnDefs: [
            { "targets": [15, 16], "searchable": false, "orderable": false },
            { "type": "html-input", "targets": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] }
        ],

    });

    $("#lines td input").on("change", function () {
        var td = $(this).parent();

        console.log($(this).parent().find("input").val());
        table.row($(this).closest("tr")).invalidate();
    });

    // Apply the search
    $("#strength_search").on("change", function () {
        table
            .columns(6)
            .search(this.value)
            .draw();
    });
    $("#dose_search").on("change", function () {
        table
            .columns(7)
            .search(this.value)
            .draw();
    });

});

HTML太多,无法粘贴到此处。小提琴会向你展示所有的东西。

EN

回答 1

Stack Overflow用户

发布于 2015-08-25 08:01:37

在主表下面创建如下内容:

代码语言:javascript
复制
 <table>
    <tr><th>Brand Name</th></tr>
    <tr><td><input id="abrand_name0" name="brand_name[]" value="" size="15" type="text"></td></tr>
        <tr><td><button id="insert" onclick="">Insert line</button></td><tr>
</table>

和添加行:

代码语言:javascript
复制
var oTable =  $('#lines').dataTable();
    oTable.fnAddData( [
        "<input name='brand_name[]' id='brand_name" + servln + "' size='15' value="+$('#abrand_name0').val()+ ">"]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32188682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档