是否可以将全局过滤器放在 p:dataTable 之外? [英] Is it possible to place the Global Filter outside the p:dataTable?

查看:12
本文介绍了是否可以将全局过滤器放在 p:dataTable 之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 p:dataTable 的全局过滤器放在表本身之外,

I need to place the global filter of the p:dataTable outside of the table itself ,

我想把它放在数据表所在的表单之外,但是为了开始将过滤器放在数据表表单内但在数据表本身之外就足够了

I would like to place it outside the form in which the datatable exists, but for start placing the filter inside the datatable FORM but outside the datatable itself will be enough

即使我将过滤器放在数据表 FORM 内但在数据表本身之外,它也会停止工作(它在 p:dataTable 本身内 100% 工作)

Even when I place the filter inside the datatable FORM but outside the datatable itself , it stop working (it works 100% inside the p:dataTable itself)

这里是过滤器本身的定义

Here is the definition of the filter itself

<p:inputText id="globalFilter" onkeyup="myTableNameTable.filter()" style="width:150px;"/>  

推荐答案

我使用代理"按钮解决了这个问题.

I solved the issue using a "proxy" button.

我用 display:none 样式设置了包围 <p:inputText id="globalFilter">h:panelGroup,像这样:

I set the h:panelGroup that surrounded the <p:inputText id="globalFilter"> with display:none style, like this:

<h:panelGroup style="display:none">  

然后在完全不同的地方添加了一个输入文本

then added an input text in completely other place

<h:panelGroup id="myFilter" >
    <h:inputText id="myFilter_text" />
</h:panelGroup>

并绑定一个使用 jQuery on() 函数的 JS 函数(在较旧的 jQuery 版本中,您可以使用 delegete()),如下所示:

And bound a JS function which uses the jQuery on() function (in older jQuery version you can use delegete()), like this:

    function searchKeyPressedHandler() {
        $(document).on("keyup", "#myFilter input", function (event) {
            var searchValue = document
                .getElementById('myFilter_text').value;

            $("#myTableId\:globalFilter").val(searchValue);
            $("#myTableId\:globalFilter").trigger('keyup')
        });
    }

使用 $() 和 on() 因为我使用了额外的 jQuery 1.7.1 库,否则我不得不使用 jQuery() 而不是

Used the $() and on() because I'm using additional jQuery 1.7.1 library, otherwise I had to use the jQuery() and instead of

$(document).on("keyup", "#myFilter input",

我会用

jQuery(document).delegate("#myFilter input","keyup",... 

(刚刚交换了第一个和第二个参数)

(just switched the first and the second arguments)

就是这样,我可以随意将过滤器输入放置在我想要的位置.

That's it, and I'm free to place the filter input where ever I want to.

这篇关于是否可以将全局过滤器放在 p:dataTable 之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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