如何从 jQuery 数据表中获取过滤后的数据结果集
How to get filtered Data result set from jQuery Datatable
如果有人能帮助我解决这个问题就太好了。
我只是想从数据表中获取过滤后的结果集。
下面是我的代码。
var filtered_row_data = $('#example').DataTable().column(1).search('186').data().unique().sort();
console.log(JSON.stringify(filtered_row_data));
它只是 returns 所有行而不是筛选值。
我正在使用最新的稳定版 Datatable。
有人可以帮忙吗?
查看数据表 selector-modifiers。您正在寻找 {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());
})
如果您正在使用服务器端过滤/搜索,这是我找到的唯一有效的解决方案:xhr event
$('#yourTable').on('xhr.dt', function ( e, settings, json, xhr ) {
//the new data is here json.data
console.log(json.data);
});
如果有人能帮助我解决这个问题就太好了。
我只是想从数据表中获取过滤后的结果集。
下面是我的代码。
var filtered_row_data = $('#example').DataTable().column(1).search('186').data().unique().sort();
console.log(JSON.stringify(filtered_row_data));
它只是 returns 所有行而不是筛选值。
我正在使用最新的稳定版 Datatable。
有人可以帮忙吗?
查看数据表 selector-modifiers。您正在寻找 {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());
})
如果您正在使用服务器端过滤/搜索,这是我找到的唯一有效的解决方案:xhr event
$('#yourTable').on('xhr.dt', function ( e, settings, json, xhr ) {
//the new data is here json.data
console.log(json.data);
});