想出答案,如果有人需要这个:
首先,使用这个数据表扩展来获取所有隐藏的行:
$.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;
}
然后过滤掉隐藏节点,只得到可见节点:
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]);
}
}