I am implementing a datatable and would like to limit the user to only be allowed to expand one datatable row at a time. If a user goes to expand a second row when another row is already expanded it will collapse the first row before expanding the second. Is this possible using primefaces? I am currently using Primefaces Version 3.0
1 Answers
PrimeFaces is just about to release an enhancement that adds a "rowToggle" event to their row expansion component. It should be in the next release after 3.3.1. It will allow you to handle the row toggle event. Once you have the ability to handle the toggle event, you will be able to write code that will collapse all rows other than the current toggled row. See here: https://code.google.com/p/primefaces/issues/detail?id=2277 which states that it will be included in the next deployment.
Note that they've already added an example of this new event to their showcase labs: http://www.primefaces.org/showcase-labs/ui/datatableExpandableRows.jsf, so it should be forthcoming.
Alternatively, you can leverage the "onExpandStart" attribute of <p:dataTable>
to invoke client side code (Javascript) to collapse any rows which are in an expanded state.