获取数据表中过滤后的列表
我正在尝试使用列中的过滤字段来过滤数据表,并获取过滤列表(填充数据表)并根据页面中过滤列表的值更新另一个组件(Toplam TL Teminati 和 Toplam Dolar Teminati)。
在 Primefaces 2.2.1 和 JSF 2 中是否可以执行此操作?如果没有,您能否推荐一个针对这种情况的解决方法?
提前致谢。
I am trying to filter a datatable using filter field in the column and get the filtered list (which populates datatable) and update another component (Toplam TL Teminati and Toplam Dolar Teminati) according to the filtered list's values in my page.
Is there anyway to do this in Primefaces 2.2.1 and JSF 2? If not can you rec commend a workaround for this case?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了向您展示我如何在 Primefaces 2.2.1 数据表中实现自定义过滤器逻辑的示例,我向您提供了我的代码的缩放版本。
无需真正深入了解有关托管 bean 代码的太多细节,命令按钮的操作本质上是将过滤器参数传递给我的 BO 层,该层重新查询数据库以获取新的
beans
列表。需要对 dataTable 组件进行显式更新来刷新数据。您会注意到,在未隐藏的显式 Beanchild Filter 按钮上,我有一个
oncomplete
属性,该属性引用名为refreshFilters()
的 javascript 函数。我不太记得我遇到的问题,但我认为这是 Primefaces 2.2.1 版本中的一个错误,当存在列过滤器值并且 dataTable 本身内发生异步更新时。这是 javascript 函数:您可以在此处看到我正在定位具有类
filtertag
的每个 DOM 元素,这将是列过滤器。我的意思是,如果服务器操作完成后该字段中存在值,那么我将手动触发keyup
事件,因为这将使用之前的值“重新过滤”该列。我不确定在 Primefaces 的更高版本中是否有必要,我什至不确定现在是否有必要,所以我建议尝试在不使用 Javascript 解决方法的情况下执行此操作,如果您在协调两者时遇到问题,那么您可以考虑使用JavaScript。
To give you an example of how I achieved custom filter logic in my Primefaces 2.2.1 dataTable, I am giving you a scaled version of my code.
Without really going into too much detail about the managed bean code, the actions of the command button are essentially passing filter arguments to my BO layer that requery the database for the new list of
beans
. The explicitupdate
of the dataTable component is needed to refresh the data.You will notice that on the explicit Beanchild Filter button that is not hidden, I have an
oncomplete
attribute that references a javascript function calledrefreshFilters()
. I can't remember exactly the problem I had, but I think it is a bug in the 2.2.1 version of Primefaces when a column filter value exists and an asynchronous update occurs within the dataTable itself. Here is the javascript function:You can see here that I am locating every DOM element that has the class
filtertag
, which would be the column filters. I am saying that if a value exists in that field after the server action is complete, then I am manually triggering akeyup
event as this will "refilter" the column with the previous value from before.I am not sure if it is necessary in later versions of Primefaces, I am not even sure it is necessary now, so I suggest trying to do this without the Javascript workaround and if you run into problems cooridnating the two then you can consider using the Javascript.