I've been using the excellent p:tree (v 3.0.M3) component with selectionmode set to checkbox. I need to provide a 'clear selection(s)' option which will remove all checked items (and any highlights) in the tree. I've done this but I just wanted to check that there's not a simpler way, as the code I have relies too much on the components internal workings.
Currently I have the following code:
Code: Select all
function unSelectAll(tree) {
tree.jq.find('.ui-tree-checkbox-icon').each(function() {
var node = $(this).parents('li:first');
tree.toggleCheckbox(node, false);
node.find('.ui-tree-node-content:first').removeClass('ui-state-highlight');
tree.removeFromSelection(node);
tree.collapseNode(node);
tree.writeSelections();
tree.fireNodeUnselectEvent(node);
});
}