Problem is short. I have created a
p:datatable
p:column
div
<p:dataTable var="user" value="#{rec.friends}" rowKey="#{user.id}" widgetVar="friendscrollist"
rendered="#{not empty rec.friends}" scrollable="true" rowIndexVar="findex"
scrollHeight="500" scrollWidth="220" selectionMode="single" selection="#{rec.chosenFriend}" styleClass="friendscroll">
<p:column width="198" id="friend#{findex}">
<div class="friendlist" onclick="friendscrollist.clickRow(#{findex})" />
</p:column>
<p:ajax update=":leftform" event="rowSelect" />
<p:ajax update=":leftform" event="rowUnselect" />
</p:dataTable>
div onclick?
the <p:dataTable widgetVar>
has unselectAllRows()
and selectRow(index)
functions which are exactly what you need.
<div onclick="friendscrollist.unselectAllRows(); friendscrollist.selectRow(#{findex})">
There's unfortunately no documentation available for those functions, but in Chrome/Firebug you can see a list of all available functions in autocomplete list when you enter friendscrollist.
in JS console. Below is a screen from Chrome:
Looking in the JS source code or common sense based on the function name should tell/hint you what those functions do.
Update: I stand corrected, a few of those functions are actually documented in PrimeFaces 3.4 User's Guide. They're in the "Client Side API" section of chapter 3.26 "DataTable", on page 146.