jQuery数据表SearchPane过滤器值 [英] JQuery Datatables SearchPane Filter Value

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

问题描述

我正在使用对Datatables的SearchPanes扩展,我试图在他们选择的SearchPane中捕获项目的值,因此看来,由于SearchPanes使用filter()而不是search(),因此该值不可用.我错了吗?

I am using the SearchPanes extension to Datatables, I am trying to capture the value of the item in the SearchPane they chose, it appears that since SearchPanes uses filter() instead of search() that value is not available. Am I wrong?

推荐答案

您可以按以下方式访问选择:

You can access the selections as follows:

1)将stateSave: true添加到DataTable初始化定义中.请参阅此示例.

1) Add stateSave: true to the DataTable initialization definition. See this example.

这将导致所有选择都保存在浏览器的本地存储.

This will cause all selections to be saved in the browser's local storage.

2)使用以下逻辑访问浏览器的本地存储:

2) Use the following logic to access the browser's local storage:

var myStorage = window.localStorage;
var searchPanes = JSON.parse(myStorage.getItem('yourStorageIndexGoesHere'));
//console.log(searchPanes); // the full JSON - large!
//console.log(searchPanes['searchPanes']['panes']); // one object per search pane
searchPanes['searchPanes']['panes'].forEach(function(pane) { 
  console.log('ID = ' + pane.id + ' - selected: ' + pane.selected); 
});

就我而言,我使用了此演示.

In my case, I used the search panes shown in this demo.

以下是带有一些选择的屏幕截图:

Here is a screenshot with some selections:

以下是上述示例将示例代码写入浏览器控制台的内容:

Here is what the sample code writes to the browser console for the above selections:

"ID"数据值是从零开始的列索引.因此,第3列(索引2)是Office列,第6列(索引5)是Salary列.

The "ID" data value is a zero-based column index. So, column 3 (index 2) is the Office column, and column 6 (index 5) is the Salary column.

相关的选定"数据是包含一个或多个值的数组.您可以迭代数组以获取每个单独的值.

The related "selected" data are arrays, containing one or more value. You can iterate the arrays to get each separate value.

您将需要用存储条目的实际名称替换yourStorageIndexGoesHere.最简单(手动)的方法是使用SearchPanes执行过滤器,然后打开浏览器工具(通常为F12).然后(假设使用FireFox)导航至存储">本地存储">,然后选择相关的键文本.

You will need to replace yourStorageIndexGoesHere with the actual name of your storage entry. The easiest (manual) way to find this is to perform a filter using SearchPanes, and then open your browser tools (usually F12). Then (assuming FireFox in my case) navigate to Storage > Local Storage > and select the relevant key text.

要注意的点:

a)假设您可以激活本地存储"功能.这意味着浏览器将记住上一次应用的过滤器,并在用户返回到DataTable浏览器页面时重新应用它.如果用户不想要该功能,那么我的解决方案将不适合您.

a) This assumes you are OK with activating the "local storage" feature. It means that the browser will remember the last applied filter, and re-apply it when a user returns to the DataTable browser page. If users do not want that feature, then my solution will not be suitable for you.

b)我无法建议您将我提供的JavaScript放在何处,因为我不知道您想用这些信息做什么.但是,例如,您可能希望在每个draw()事件之后使用它-在这种情况下,请参见此处.

b) I can't advise you on where you need to place the JavaScript I provided, because I don't know what you want to do with this information. But, for example, you might want to use it after every draw() event - in which case, see here.

这篇关于jQuery数据表SearchPane过滤器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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