数据属性的数据表搜索

datatable search on data attribute

为我构建的数据表html 和 js 代码

<button class="test">test</button>
<table id="example2" class="display table " width="100%">
    <thead>
        <tr>
            <th>Code</th>
            <th>Email</th>
            <th>Status</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>abc12345</td>
            <td data-search="derrick1@gmail.com"><input name="email[]" id="row-email-0" value="derrick1@gmail.com"  /></td>
            <td>N/A</td>
        </tr>
    </tbody>
</table>

<script>
var theTable = $('#example2').DataTable({
                    "ordering": false
                });

theTable.row.add([
    'abc432',
    '<input name="email[]" id="row-email-\' + rowIndex + \'" value="" />',
    'N/A'
]).draw(false)
</script>

如何根据数据表的 row.add 方法设置数据搜索属性?

看这个 -> https://datatables.net/forums/discussion/42814/requested-unknown-parameter-object-object ...你可以这样包含一个 data-search 属性:

theTable.row.add({
    0 : 'abc432',
    1: {
      display: '<input name="email[]" id="row-email-\' + rowIndex + \'" value="" />',
      '@data-search': 'something'
    },
    2 : 'N/A'
}).draw(false)

使用您的代码进行演示 -> https://jsfiddle.net/h7Lno4yx/