Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marekdano/2a98aba3843dfc787fdcf55f941b22a5 to your computer and use it in GitHub Desktop.
Save marekdano/2a98aba3843dfc787fdcf55f941b22a5 to your computer and use it in GitHub Desktop.
/**
* Function finds the node you are searching for and expand it and its parent.
*
* @param {TreeNode} node primeng tree node data
* @param {string} propField name of the property you are searching for ex: label
* @param {any} searchValue value you are searching for
*/
filterExpandRecursive(
node: TreeNode,
propField: string,
searchValue: any
): boolean {
const isMatchSearchField = node[propField] === searchValue;
node.expanded =
node.children &&
node.children.length > 0 &&
node.children.some(childNode =>
this.filterExpandRecursive(childNode, propField, searchValue)
);
return isMatchSearchField || node.expanded;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment