如何从 jQuery Datatable 中获取过滤后的数据结果集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33169649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:56:35  来源:igfitidea点击:

How to get filtered Data result set from jQuery Datatable

jquerydatatablesdatatables-1.10

提问by Raja

It would be great if someone help me on the issue.

如果有人在这个问题上帮助我,那就太好了。

I am just trying to get the filtered result set from the Datatable.

我只是想从数据表中获取过滤后的结果集。

Below is my code.

下面是我的代码。

var filtered_row_data = $('#example').DataTable().column(1).search('186').data().unique().sort();

 console.log(JSON.stringify(filtered_row_data));

It just returns all the rows instead of filtered values.

它只返回所有行而不是过滤值。

I am using latest stable version of Datatable.

我正在使用 Datatable 的最新稳定版本。

Can anyone please help on this?

任何人都可以帮忙吗?

回答by davidkonrad

see dataTables selector-modifiers. You are looking for {filter : 'applied'}:

请参阅数据表选择器修饰符。您正在寻找{filter : 'applied'}

table.on('search.dt', function() {
    //number of filtered rows
    console.log(table.rows( { filter : 'applied'} ).nodes().length);
    //filtered rows data as arrays
    console.log(table.rows( { filter : 'applied'} ).data());                                  
})  

demo -> http://jsfiddle.net/h4wrmfx3/

演示 -> http://jsfiddle.net/h4wrmfx3/

回答by Adel Mourad

if you are using server side filtering / searching, this is the only solution i found and it works: xhr event

如果您使用服务器端过滤/搜索,这是我找到的唯一解决方案,它有效:xhr 事件

$('#yourTable').on('xhr.dt', function ( e, settings, json, xhr ) {
        //the new data is here json.data
        console.log(json.data);
});