In my application I have a <p:datatable>
with rowExpansion
column. I have a requirement to open a single row at a time. If anyone tries to expand second row, remaining first row expanded then one message will be generated saying First close the expanded row and then open another row
.
How this can be implemented ? Any pointer will be very helpful to me. Thanks
you can achieve this with the help of this custom method.
give 'togglerClass' this class like
JavaScript code here;
call this method in windows ready.
Check out the
datatable.js
file in Primefaces here. There is a javascript function calledtoggleExpansion
.Maybe you can override this function and call the original one when no row is expanded and show a message when another row is already expanded (and not call the original one).
Just an idea...
You can use (I have tested it in mojarra 2.1.20 and Primefaces 3.5 and it works fine) the following solution which calls a JavaScript function when the row is expanded. When clicking on a second row, and there is another expanded row, it will trigger a
click
event, which will in turn collapse the previously opened row.xhtml:
Javascript:
As of 2015, and this question is first in Google search results, I want to add that for PrimeFaces 5.1, there is dataTable attribute
rowExpandMode
, when set tosingle
- allows only one row to be shown. Example:It's not exactly what was asked, but I hope that it'll help to others.