jsfprimefacesprimefaces-datatable

Clear PrimeFaces TreeTable selection


How to implement a "Clear All Selection" button which will uncheck all selected things from a TreeTable implemented using PrimeFaces 6.2


Solution

  • I would use the client side API for this. It allows you to unselectAllNodes. You can use it in combination with the widgetVar of your tree table:

    PF('yourWidgetVar').unselectAllNodes()
    

    In a button, use it like:

    <p:button value="Clear selection"
              onclick="PF('yourWidgetVar').unselectAllNodes();return false"/>
    

    Note that the linked documentation applies to the latest release, but the unselectAllNodes function is also present in 6.2: https://github.com/primefaces/primefaces/blob/6_2/src/main/resources/META-INF/resources/primefaces/treetable/treetable.js#L701-L709