Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the focus of the inputText inside dataTable

Good Afternoon,

Using JSF + Primefaces. I have a dataTable with inputText field, which performs a listner, and when you end the function or pressing tab, the focus would be to input the low line of the same component.

Googled some things, and it seems that's to be done with JavaScript or jQuery, but I have not much knowledge.

It seems that the clientId of the component has something form: dataTable: 0: input, and the number "0" to manipulate the focus. Anyone know how to work the focus of components within the dataTable?

Thank you.

like image 747
Wilson Ribeiro Avatar asked Jan 07 '14 15:01

Wilson Ribeiro


1 Answers

You could use the PrimeFaces element <p:focus />, and in the "context" attribute, put the ID of the dataTable. The "context" attribute serves to set the root component to start first input search, so if you are using AJAX, you could update the container where the "dataTable" and the "focus" elements are wrapped, and the first input in the dataTable will recieve the focus after AJAX call:

<p:focus context="dataTable" />

You could use the "for" attribute too, if you want to refer the input directly:

<p:focus for="inputText" />

Take a look to the PrimeFaces documentation: p:focus.

like image 181
Julian David Avatar answered Sep 28 '22 02:09

Julian David