数据表列搜索。选择要替换为输入字段的列

Datatables columns search. Selecting columns to replace with input fields

我正在使用数据tables 根据此示例创建具有可搜索列的 table: https://datatables.net/examples/api/multi_filter.html

问题是,我只需要在某些列上使用过滤器,我可以 select 像这样“.columns([0,2,4])”

这是将 headers 更改为 所有 列的输入字段的脚本:

$('#example tfoot th').each( function () {
        var title = $('#example thead th').eq( $(this).index() ).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );

我应该放在哪里

.columns([0,2,4]

它只转换这些列的 headers?

您可以在 jquery 中使用 CSS 过滤器来继续只搜索那些需要的列,如下所示:

$('#example tfoot th:nth-child(1),th:nth-child(3),th:nth-child(5)').each( function () {
        var title = $('#example thead th').eq( $(this).index() ).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );

DEMO