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…