robert trudel
robert trudel

Reputation: 5749

Datatable get data attribute on click row

I use datatable

A typical row is

<tr>
      <td data-id="1">Tiger Nixon</td>
      <td>System Architect</td>
      <td>Edinburgh</td>
      <td>61</td>
      <td>2011/04/25</td>
      <td>$320,800</td>
</tr>

I created an example

http://jsfiddle.net/hb7v1mgy/

Init of the table

 var table = $('#example').DataTable({
    responsive: true
  });

When I click on a row, I would like to get data attritube id, actually I get column value (Tiger, System...)

$('#example tbody').on('click', 'tr', function() {
    //get only value of td... not data attribute
    var data = table.row(this).data();
});

Upvotes: 1

Views: 5761

Answers (1)

Marc Collin
Marc Collin

Reputation: 499

In your click method

var tr = $(this).closest('tr');
var id = tr.children("td:eq(0)").attr('data-id')

you don't need select plugin...

Upvotes: 4

Related Questions