selecting row(s) via javascript in p:datatable

Hi,

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"
selectionMode="single"
selection="#{someBean.someData}">

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

...

</p:datatable>

with the help of

onclick="datatableVar.unselectAllRows();datatableVar.selectRow(#{rowIndex})"

, 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…

Advertisements

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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s