selecting row(s) via javascript in p:datatable


with PrimeFaces things can be so easy that you cannot even imagine. Lastly a requirement came to me to select a row ( or rows ) with javascript for the p:datatable. The thing I did was like this:

<p:dataTable rowIndexVar="rowIndex"  widgetVar="datatableVar"

<f:facet name="header">
<h:outputText value="Select"/>
<h:graphicImage value="/images/selectImage.gif"  onclick="datatableVar.unselectAllRows();datatableVar.selectRow(#{rowIndex})"/>



with the help of


, I removed the previous selections and added the new selection. As you see it is very easy to do stuff with PrimeFaces. By the way as the datatable will be re-written in the new version, this may not work in the future but currently it works nicely…

3 thoughts on “selecting row(s) via javascript in p:datatable

  1. It would be nice to update the doc with these features. I was looking for kinda functionality. Thanks for the post

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s