gpt4 book ai didi

filtering - jQuery dataTables - 获取过滤的列值

转载 作者:行者123 更新时间:2023-12-03 22:06:28 27 4
gpt4 key购买 nike

我正在使用 jQuery dataTable,当用户选择下拉菜单时,它会搜索数据表并对其进行过滤,并根据搜索到的数据重新绘制内容:

mtTable.columns().each(function() {
mtTable.column(22).search(searchVal, true, true).draw();
});

现在我试图在搜索完成后获取所有列值,但是我找不到执行此操作的函数。目前我正在使用 api

var myTable = $("#tblResults").DataTable();
var resultsArray = myTable.columns(colIndex).data();

根据文档,这将返回未过滤的列中的所有数据。我找不到一个函数来为我提供仅筛选数据的列值数组。

最佳答案

您可以在此处阅读有关 dataTables 高级选择器修饰符的所有内容 -> http://datatables.net/reference/type/selector-modifier

如果您只想获取过滤行:

table.rows( { search:'applied' } ).data().each(function(value, index) {
console.log(value, index);
});

要定位特定列,并仅获取过滤后的值(您的特定请求) - 这里是第 2 列中的所有过滤后的值:

table.column(2, { search:'applied' } ).data().each(function(value, index) {
console.log(value, index);
});

查看演示 -> http://jsfiddle.net/q0e1bdcz/

要根据特定列的过滤值创建数组:

var array = [];
table.column(2, { search:'applied' } ).data().each(function(value, index) {
array.push(value);
});
console.log(array);

查看演示 -> http://jsfiddle.net/q0e1bdcz/1/

关于filtering - jQuery dataTables - 获取过滤的列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27159614/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com