Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery DataTables fnGetData

I am using jQuery DataTables 1.10 plugin. In the earlier version, (1.9.4 plugin) I was able to get data from table like this:

var iPos = oTable.fnGetPosition( this );
var aData = oTable.fnGetData( iPos );

Now, using the same code, I am getting the error

TypeError: aData is null

How can I use the new functionallity? I tried using oTable.row(iPos).data() but didn't worked for me

like image 995
rosuandreimihai Avatar asked Mar 20 '23 06:03

rosuandreimihai


1 Answers

You're trying to access the 1.10 API with the older API methods. fnGetData has been deprecated, as you're seeing. For starters, the Hungarian Notation (mData, fnRedraw) is gone.....it's about time!

The new method is pretty straightforward:

Example to get data from a clicked cell:

var table = $('#example').DataTable();

$('#example tbody').on( 'click', 'td', function () {
    var cellData = table.cell( this ).data();
} );

Example to get data from a clicked row:

var table = $('#example').DataTable();

$('#example tbody').on( 'click', 'tr', function () {
    var rowData = table.row( this ).data();
} );

Here's the API reference for other questions. You might also benefit from the API conversion guide, where you can look up old functions and see their new equivalents.

like image 87
bpeterson76 Avatar answered Mar 28 '23 03:03

bpeterson76