Joelio
Joelio

Reputation: 4691

How can I get a class from a jQuery datatable row object?

I have a jQuery datatable row:

 table = $('#reports').DataTable()
 row = table.row(rowIndex)

How do I get the HTML class from it? (It is striped, and I want to find out if it is odd or even.)

I have tried:

row.hasClass('odd')

row.className

row.attr('class')

Any ideas?

Upvotes: 7

Views: 14237

Answers (3)

davidkonrad
davidkonrad

Reputation: 85528

It is a really a good question. The ordinary jQuery way, by using row.index():

var rowClass = $("#example tbody tr:eq(" + row.index() + ")").attr('class');

Proof of concept -> http://jsfiddle.net/7jy46wz4/

Upvotes: 3

Jonathan Queipo
Jonathan Queipo

Reputation: 66

Taking what @rick-hitchcock said, another approach is to use the following code in validations:

var hasOddClass = $(row.node).hasClass("odd");

which, by the examples you gave, should be closer to what you want.

Upvotes: 0

Rick Hitchcock
Rick Hitchcock

Reputation: 35670

Use node with className:

row.node().className;

Upvotes: 7

Related Questions