330xi
330xi

Reputation: 97

Avoid focus in datatable filter in dialog

I have a popup dialog with datatable and I want to have no focus in filter inputText fields. I want to have focus on button under this table. I tried this:

<p:focus id="focus" for="buttonFocus" context="dialog"/>
<p:dialog id="dialog" header="Выбор организации" widgetVar="vDialog" modal="true" resizable="false">  
    <p:dataTable 
    dblClickSelect="true"
    id="table"               
                 var="record"
                 value="#{myBean.tableList}"
                 rowKey="#{record.waId}"
                 filteredValue="#{myBean.filteredList}" 
                 lazy="true"                                                             
                 >                                                                      
                <p:column headerText="Name" filterBy="#{recordp.name}" sortBy="#{recordp.name}">                                    
                         #{record.name}
                </p:column>                                                                                                 
     </p:dataTable>  
        <p:commandButton id="buttonFocus" actionListener="#{myBean.fill}"/>     
</p:dialog>

it doesn't help. So, how to set focus on button in such situation?

Upvotes: 0

Views: 1709

Answers (1)

Darka
Darka

Reputation: 2768

I found several suggestions.

So first one, which worked for me is:

       <script type="text/javascript">

       PrimeFaces.widget.Dialog.prototype.applyFocus = function() {
          var firstInput = this.jq.find('#buttonFocus');
              firstInput.focus();
       }
       </script>

You don't need p:focus for this method. And also don't forget add prependId="false" to form, because otherwise id will change.

Second which worked with input elements only (not with button):

       <script type="text/javascript">

       PrimeFaces.widget.Dialog.prototype.applyFocus = function() {

       }
       </script>

Here you need p:focus element, but like I said this works with inputs only.

And third solution you can look in this blog , if you have right versions of primefaces (not tested)

Upvotes: 1

Related Questions