Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 982
Joelio Avatar asked Mar 06 '15 20:03

Joelio


People also ask

What is the row selector?

The row selector is a component that acts like a visual filter for datasets. It takes one dataset, chops it up into various ranges based on its configuration, and lets the user choose the splices. Then it creates a virtual dataset that only contains the rows that match the selected splices.

How can get current TR data in jQuery?

$(this). closest('tr'). children('td:eq(0)'). text();

What is Rowcallback in DataTable?

Description. This callback allows you to 'post process' each row after it have been generated for each table draw, but before it is rendered into the document. This means that the contents of the row might not have dimensions ( $(). width() for example) if it is not already in the document.

What is jQuery DataTable?

Introduction to jQuery Data Table jQuery DataTable is a powerful and smart HTML table enhancing plugin provided by jQuery JavaScript library.

How do I use DataTables?

To use DataTables, the first step is to include the jQuery library since it is a jQuery plugin. Secondly, two additional files need to be included to get DataTables running on your website.

Is DataTables client side or server side?

It supports both client-side processing as well as server-side processing. To use DataTables, the first step is to include the jQuery library since it is a jQuery plugin. Secondly, two additional files need to be included to get DataTables running on your website.

How do I get an object by class in HTML?

Refresh the index.html document in your browser, and click on the Test Button input; the get object by class is activated, and the result is shown in Figure C as displayed in Chrome 17.0.9:


Video Answer


2 Answers

Use node with className:

row.node().className;
like image 116
Rick Hitchcock Avatar answered Oct 21 '22 04:10

Rick Hitchcock


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/

like image 39
davidkonrad Avatar answered Oct 21 '22 04:10

davidkonrad