4

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

1
  • datatables.net? if not can you add a link? Commented Jun 22, 2014 at 20:17

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Legacy functions such as fnGetData are still available, for example $('#example').dataTable().fnGetData().
From a maintainability standpoint, it makes ZERO sense to write new code using an old API, and will only make you more confused when you go to the website for support and realize that all your documentation has been buried. You're right, at least for 1.10, that you can still use the old API. But there's no guarantee going forward. There are also definitely examples of some functions being no longer supported, such as fnRender.
I agree with you regarding using deprecated functions, but my point is that they're still available when you're stating the opposite. There might be other reason fnGetData didn't work for OP.
There is a difference between .dataTable you use and .DataTable that he used. Since I'm not using legacy API, I'd have to dig in to know which one has each method available, but it's something for the OP to check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.