过滤JQuery Datatables后检索行数据 [英] Retrieving row data after filtering JQuery Datatables
本文介绍了过滤JQuery Datatables后检索行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看起来应该很简单,但...
Seems like it should be easy but...
有谁知道如何从过滤的dataTable返回当前行? oTable.fnGetNodes()
方法返回所有行,我只想要过滤(可见,但包括分页)一个
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
我检查了:从Datatables中检索可见数据,但没有太多帮助。
I checked: Retrieving visible data from Datatables but not much help there.
推荐答案
确定答案,如果有人需要这样做:
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]);
}
}
这篇关于过滤JQuery Datatables后检索行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文