含糊的multi_select过滤器-AND和OR条件-javascript [英] ambiguous multi_select filter - AND and OR condition - javascript
问题描述
multi_select filter with select2 in yadcf (datatables plugin) has a ambiguous solution for filtering. If you have inside rows single values like
value1
value2
过滤时具有OR
过滤.它显示具有value1和values2的所有行.
如果设置文本分隔符(如逗号)或多个分隔符(使用正则表达式),则multi_select过滤器的行为与AND
条件相同.
查看第0列的示例:示例
是否可以根据您的需要启用javascript功能,或者启用AND条件或OR条件?
when you filtering you have a OR
filtering. It shows all rows with values1 and values2.
If you set a text delimiter like a comma or multiple delimiters (using regex) multiple_select filter behaves as a AND
condition.
Look an example for column 0: Example
Is possible to have a javascript function that enables or an AND condition or an OR condition according to suit your needs?
为了获得更好的曝光效果,我制作了一些视频,介绍了问题所在以及希望在表中看到的内容.
问题很棘手,但是使用正确的javascript代码应该不难解决
For better exposure I made a little video of what the problem is and what I expect to see in the table.
Problem is tricky but It should not be difficult to solve with right javascript code
--------------------------------------------------- --------------------------------
-------------------------------------------------- -----------------------------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
添加功能改进请求:
视频中使用的示例:表
推荐答案
文本定界符的目的是帮助您将列中的值提取到过滤器中,但是...当您尝试从列中选择一个值时过滤并将其应用于表格,您将获得所选值所在的所有行.
The purpose of the text delimiter is to help you extract values from your column into the filter, but... when you try to pick up a value from the filter and apply it to the table, you will get all the rows that your selected value is located in.
如果希望在拾取值时执行如此高级的逻辑,则应使用filter_type: 'custom_func'
或multi_select_custom_func
来查看它如何在展示柜(位于第一列)向下滚动以查看该页面上使用的代码.
In case that you want so advanced logic to be executed when you pick up a value you should then use the filter_type: 'custom_func'
or multi_select_custom_func
see how it works on the showcase (its the first column) scroll down to the see the code used on that page.
最后,我了解了您的问题,尽管多选始终可以对选定的值进行或"过滤,但是我已经在更新了jsfiddle
Finally I understood your problem, while the multi select should always work as OR filter on the selected values it wasn't doing so, I have fixed it in the latest beta 0.8.8.beta.11 and here is an updated jsfiddle
关于您的 AND 问题:您无法使用mutli select + text_data_delimiter
图像来完成此操作,因为该图像具有包含AAA,BBB的列,现在您的用户可以选择AAA,然后选择BBB(工作),但他还可以选择BBB,然后选择AAA,并且没有可将BBB,AAA识别为AAA,BBB的正则表达式(这只是一个小例子)
Regarding your AND question: You can't accomplish it with mutli select + text_data_delimiter
image that you have a column with AAA, BBB and now your user can select AAA then BBB (that should work) but he can also select BBB and then AAA, and there is no regex that can spot the BBB, AAA as AAA, BBB (and that was just a small example)
因此最好的解决方案是在具有text_data_delimiter的filter_type: "multi_select"
到(没有text_data_delimiter的filter_type: "multi_select"
或filter_type: "select"
)之间切换
So the best solution would be to switch between filter_type: "multi_select"
with text_data_delimiter to (filter_type: "multi_select"
without text_data_delimiter or filter_type: "select"
)
并且已经有一个与此相关的类似问题(不确定何时会实施)
And there is already a similar issue open for that (not sure when I will implement it)
这篇关于含糊的multi_select过滤器-AND和OR条件-javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!