Retrieving row data after filtering JQuery Datatables
datatables, jquery
Solution
Figured out the answer, if anyone ever needs this:
First, using this datatables extension to get all the hidden rows:
$.fn.dataTableExt.oApi.fnGetHiddenTrNodes = function (oSettings, arg1, arg2) {
/* Note the use of a DataTables 'private' function thought the 'oApi' object */
var anNodes = this.oApi._fnGetTrNodes(oSettings);
var anDisplay = $('tbody tr', oSettings.nTable);
/* Remove nodes which are being displayed */
for (var i = 0; i < anDisplay.length; i++) {
var iIndex = jQuery.inArray(anDisplay[i], anNodes);
if (iIndex != -1) {
anNodes.splice(iIndex, 1);
}
}
/* Fire back the array to the caller */
return anNodes;
}
Then filter out the hidden nodes to get only visible nodes:
var rows = oTable.fnGetNodes(); // get all nodes
var rows_hidden = oTable.fnGetHiddenTrNodes(); // get all hidden nodes
var result = [], found;
// remove hidden nodes from all nodes
for (var i = 0; i < rows.length; i++) {
found = false;
for (var j = 0; j < rows_hidden.length; j++) {
if (rows[i] == rows_hidden[j]) {
found = true;
break;
}
}
if (!found) {
result.push(rows[i]);
}
}
Problem
Seems like it should be easy but... Does anyone know how to return the current rows from a filtered dataTable? The `oTable.fnGetNodes()` method returns all rows, where I just want the filtered (visible, but including paginated) ones ``` // filter on division var oTable = $('#summary-table').dataTable(); oTable.fnFilter(division_text, 2, true); // Get the nodes from the table var nNodes = oTable.fnGetNodes(); // <-- still retrieves original list of rows ``` I checked: Retrieving visible data from Datatables but not much help there.