jQuery dataTables - 获取过滤的列值 [英] jQuery dataTables - get filtered column values

查看:164
本文介绍了jQuery dataTables - 获取过滤的列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using a jQuery dataTable and when the user selects a drop down it searches the data table and filters it and redraws the contents based upon the searched data :

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

现在我尝试在搜索完成后获取所有的列值,但是我找不到这样做的功能。目前我正在使用api

Now I am trying to get all of the column values after a search is done, however I cannot find a function to do this. Currently I am using from the api

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

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

According to the documentation this will return all of the data from within the column unfiltered. I cannot find a function to give me an array of the column values for the filtered data only.

推荐答案

您可以在这里阅读关于dataTable的所有高级 selector-modifiers > http://datatables.net/reference/type/selector-modifier

You can read all about dataTables advanced selector-modifiers here -> http://datatables.net/reference/type/selector-modifier

如果您只想获得过滤行:

If you want to get filtered rows only :

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

定位一个特定的列,并仅获取过滤的值(您的特定请求) - 这里所有过滤的值从列#2:

To target a specific column, and get filtered values only (your specific request) - here all filtered values from column #2 :

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

请参见演示 - > http://jsfiddle.net/q0e1bdcz/

See demo with both -> http://jsfiddle.net/q0e1bdcz/

通过过滤值创建数组对于特定列:

To create an array over filtered values for a specific column :

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

请参阅demo - > http://jsfiddle.net/q0e1bdcz/1/

See demo -> http://jsfiddle.net/q0e1bdcz/1/

这篇关于jQuery dataTables - 获取过滤的列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆