Trigger JavaScript action after Datatable is loaded

Posted by perissf on Stack Overflow See other posts from Stack Overflow or by perissf
Published on 2012-06-10T20:02:18Z Indexed on 2012/06/10 22:40 UTC
Read the original article Hit count: 247

Filed under:
|
|

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

In order to better understand the scenario, on page load the dataTable is not rendered. It is rendered 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, I have a JavaScript hook after the successful login, if it can be of any help. Immediately after the oncomplete action has finished, the update attribute renders the dataTable:

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

After the datatable is loaded, I need to run a JavaScript function on each row item, in order to subscribe to a cometD topic.

In theory I could use the oncomplete attribute of the login Button for triggering a property from myBean in order to retrieve once again the values to be displayed in the dataTable, but it doesn't seem very elegant.

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

function javaScriptFunctionToBeTriggered(rowKey) {
    // do something
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jsf