Retrieving Visible Data From Datatables
Solution 1:
The underscrore (_) method is particularly useful here. It's worked well for me in the past. It will return an array of objects.
oTable._('tr', {"filter":"applied"});
Solution 2:
The fnGetData
method is the correct (for Datatables version <= 1.10) way to extract data:
http://legacy.datatables.net/api#fnGetData
Per that documentation that function will:
Get the data for the whole table, an individual row or an individual cell based on the provided parameters.
Here's an example from that documentation:
oTable = $('#example').dataTable();
oTable.$('tr').click( function () {
var data = oTable.fnGetData( this );
// ... do something with the array / object of data for the row
});
NOTE: My original answer mentioned using fnGetData
without an argument (which worked for me a long time ago), and the docs suggest that should still work ("the data for the whole table"), but since that answer got down-voted and documentation doesn't specifically provide an example of its usage, I'm going to avoid recommending using it that way.
Of course, the old Datatables is kind of terrible, so most likely (unless you have a lot of code built around the old Datables) your best bet is to upgrade to the newest version (or to another table/grid library entirely).
Post a Comment for "Retrieving Visible Data From Datatables"