Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to close all nodes #65

Open
Charming2015 opened this issue May 7, 2021 · 2 comments
Open

how to close all nodes #65

Charming2015 opened this issue May 7, 2021 · 2 comments

Comments

@Charming2015
Copy link

how to close all nodes?

@nosferatu500
Copy link

isOpenByDefault: false

@gregjoeval
Copy link

gregjoeval commented Aug 30, 2022

this is what I've done, hope this helps

  const ref = useRef<FixedSizeTree<ITreeWalkerData>>(null);

  const collapseAllNodes = useCallback(async () => {
    await ref.current?.recomputeTree(
      Object.fromEntries(
        // Note: This is for a tree with multiple root nodes
        rootNodes.map(
          (m): RecomputeTreeKeyValuePair => [
            createNodeId(m.key),
            {
              open: false,
              subtreeCallback: (node) => {
                // NOTE: this is permitted by the library and is faster than using setOpen
                node.isOpen = false;
              },
            },
          ]
        )
      )
    );
  }, [rootNodes]);

  return (
    <div>
      <button onClick={collapseAllNodes}>Collapse All</button>
      <FixedSizeTree
        ...
        ref={ref}
      >
        ...
      </FixedSizeTree>
    </div>
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants