4

i've built up a table with dataTable jQuery plugin. I am trying to get the td data of a tr element by clicking on that tr. I've read the documentation which says that i have to use "fnGetData", but when i try that, i get the error:

TypeError: table.fnGetData is not a function

var data = table.fnGetData( this );

My js Code:

 $('#customerTable tbody').on('click','tr', function(){
    var data = table.fnGetData( this );
    alert(data);
});

My DataTable is initialized as the following, working well without the click event:

var table = $('#customerTable').DataTable( {..});

Do I have to bind another plugin script in my html head section?

Regards.

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
user3746259
  • 1,491
  • 2
  • 23
  • 46
  • I can not test it right now, but Why not bind the click directly on the tr in the first place? – alexdd55 Jun 16 '14 at 20:22
  • Can you please provide some sample code, i don't quite understand what you mean by "directly on the tr in the first place". Regards EDIT: I thought it would be good to use the method of dataTable to access the data. Sure i can build a workaround with "pure jquery", but i think the dataTable method with fnGetData is better. – user3746259 Jun 16 '14 at 20:26
  • Ok i just found out that i have to use a special plugin for that from dataTables. Was not described very well in their documentation: – user3746259 Jun 16 '14 at 20:52
  • 1
    Yeah, their docs are crap – alexdd55 Jun 16 '14 at 20:53
  • Yep, they want to make money by purchasing support .. nevermind, thanks for your attention to help :) – user3746259 Jun 16 '14 at 21:15
  • To me it seems there is a difference if you initialize it with `dataTable({...})` vs `DataTable({...})`. http://jsfiddle.net/vt573y28/ – Danny Apr 15 '15 at 16:31

1 Answers1

4

It seems there is a difference in the API datatables provides whether you initialize it with DataTable({..}) vs dataTable({..}). The differences can be seen here.

Since you initialized it with the newer API you should instead in your listener use.

var data = table.row( this.rowIndex-1 ).data();

Example

If you used dataTable({..}) to initialize your table the code that you posted should work.

Example

Community
  • 1
  • 1
Danny
  • 7,368
  • 8
  • 46
  • 70