Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
941 views
in Technique[技术] by (71.8m points)

jsf 2 - Is it possible to place the Global Filter outside the 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

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;"/>  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I solved the issue using a "proxy" button.

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>

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')
        });
    }

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",

I would use

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...