Iverson
Iverson

Reputation: 179

datatable search on data attribute

Having this html and js code for my constructed datatable

<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="[email protected]"><input name="email[]" id="row-email-0" value="[email protected]"  /></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>

How do I set the data-search attribute upon datatable's row.add method?

Upvotes: 1

Views: 546

Answers (1)

davidkonrad
davidkonrad

Reputation: 85578

See this -> https://datatables.net/forums/discussion/42814/requested-unknown-parameter-object-object ...You can include a data-search attribute this way:

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

demo with your code -> https://jsfiddle.net/h7Lno4yx/

Upvotes: 1

Related Questions