如何以编程方式应用 DataTable 过滤器?

编程入门 行业动态 更新时间:2024-10-12 03:17:06
本文介绍了如何以编程方式应用 DataTable 过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用 PrimeFaces Demo 过滤 DataTable (www.primefaces/showcase/ui/data/datatable/filter.xhtml) 为例,我希望能够在表格外提供过滤"链接供用户点击(比如沃尔沃、福特、宝马等).当用户单击链接时,我想在制造商过滤器下拉列表中切换所选项目并应用过滤器.我一直无法弄清楚如何进入过滤器属性进行更改.这可以通过javascript完成吗?如何访问选择列表并设置当前选择?

Using the PrimeFaces Demo filtering DataTable (www.primefaces/showcase/ui/data/datatable/filter.xhtml) as an example, I would like to be able to provide "filtering" links outside of the table for the user to click (say Volvo, Forw, BMW, etc). When the user clicks the link, I would like to switch the selected item in the manufacturer filter dropdown and apply the filter. I haven't been able to figure out how to get to the filter properties to make the change. Can this be done via javascript? How do I access the selection list and set the current selection?

更新:按照丹尼尔的链接,我设法改变了下拉选择,但我无法应用过滤器.在过滤器基于输入字段的列中,触发 keyup 会导致数据过滤,但我无法弄清楚在选择上触发什么事件以使其过滤.这是我正在使用的代码:

UPDATE: Following Daniel's link, I managed to get the dropdown selection to change, but I am unable to get the filter to apply. In the columns where the filters are based on an input field, triggering the keyup causes the data to filter but I can't figure out what event to trigger on the select to make it filter. Here is the code I am using:

<p:commandLink id="filterLink" value="Click to filter to Volvo Only" onclick="$('#carForm\\:dataTable\\:manufacturerColumn_filter').val('Volvo'), $('#carForm\\:dataTable\\:manufacturerColumn_filter').trigger('filter')" />

上面创建的链接会将制造商过滤器切换为沃尔沃,但不会导致数据过滤.

The link created by the above will switch the Manufacturer filter to Volvo but will not cause the data to filter.

推荐答案

关键是在表层调用过滤事件.所以我上面的代码应该是:

The key is to call the filter event at the table level. So my code above should properly be:

<p:commandLink id="filterLink" value="Click to filter to Volvo Only" onclick="$('#carForm\\:dataTable\\:manufacturerColumn_filter').val('Volvo'), carsTable.filter()" />

更多推荐

如何以编程方式应用 DataTable 过滤器?

本文发布于:2023-11-09 21:15:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573458.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   方式   DataTable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!