JavaScript trigger action after loading datatable

In the JSF 2.1 + PrimeFaces 3.2 web application, I need to run the JavaScript function after loading p:dataTable . I know that there is no such event in this component, so I have to find a workaround.

To better understand the scenario, the dataTable is not displayed when the page loads. It is displayed after a successful login:

 <p:commandButton value="Login" update=":aComponentHoldingMyDataTable" action="#{loginBean.login}" oncomplete="handleLoginRequest(xhr, status, args)"/> 

As you can see from the above code, after a successful login, I have a JavaScript hook if it can be useful. The update attribute causes the dataTable rendering attribute to overestimate:

 <p:dataTable var="person" value="#{myBean.lazyModel}" rendered="#{p:userPrincipal() != null}" /> 

After loading the datatable, I need to run a JavaScript function for each element of the string in order to subscribe to cometD .

In theory, I could use the oncomplete attribute of the oncomplete button to launch the property from myBean , to get the values ​​that will be displayed in the dataTable again, but that doesn't seem very elegant.

The JavaScript function should do something with the rowKey each row of dataTable:

 function javaScriptFunctionToBeTriggered(rowKey) { // do something } 
+4
source share
2 answers

The javascript method from the oncomplete attribute oncomplete called after the completion of the ajax request and, therefore, after loading the dataTable.

So you can do the following:

 <p:commandButton ... oncomplete="doSomething()"/> 

and everything should work fine.

+3
source

if the page reloads, try making a call in the document:

 $(document).ready(function() { doSomething(); }); 
0
source

All Articles