10

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>

Is it possible? How to do it? Thanks.

1

1 Answer 1

35

So I found out, what I needed was to set my attributes dynamically, it's possible using the data parameter of the function, it contains the model corresponding to the row.

    var table = $('#incidentTable').DataTable({
        createdRow: function (row, data, dataIndex) {
            $(row).attr('data-id', data.Id);
            $(row).attr('data-ownerid', data.OwnerId);
        }
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.