how to add data-attributes to the rows of a JQuery DataTable

Ale*_*lex 2 datatable jquery datatables

I would like to had (multiple) data-attributes to the generated rows of my JQuery DataTable so that I can store data in it.

What I want to achieve is to make DataTables generate something like this:

<tr data-foo="bar">
  <td></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

Is it possible? How to do it? Thanks.

Ale*_*lex 9

因此我发现,我需要动态设置属性,可以使用函数的data参数,其中包含与行相对应的模型。

    var table = $('#incidentTable').DataTable({
        createdRow: function (row, data, dataIndex) {
            $(row).attr('data-id', data.Id);
            $(row).attr('data-ownerid', data.OwnerId);
        }
    });
Run Code Online (Sandbox Code Playgroud)