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

node.addChildren() won't display newly created node when filter extension is active #1054

Closed
zadam opened this issue Nov 28, 2020 · 2 comments

Comments

@zadam
Copy link

zadam commented Nov 28, 2020

Expected and Actual Behavior

I have active filter:

this.tree.filterBranches(node => node.data.noteId === 'XXX');

filter settings is set globally as:

filter: {
    counter: false,
    mode: "hide",
    autoExpand: true
}

I have fully initialized tree and then later I'm adding a new additional node like this:

parentNode.addChildren([
  { ... }
]);

Now what happens is this:

image

So the new node is not visible, however it is added to the DOM:

image

It's not visible because it has fancytree-hide class.

Now very interestingly, when I press e.g. arrow down or up (thus changing focused node), this newly created node appears:

image

the code responsible for setting fancytree-hide is in function nodeRenderStatus:

$span
	.toggleClass("fancytree-match", !!node.match)
	.toggleClass("fancytree-submatch", !!node.subMatchCount)
	.toggleClass(
		"fancytree-hide",
		!(node.match || node.subMatchCount)
	);

And debugger shows that for this newly created node the node.match and node.subMatchCount are both undefined. Node should be displayed because I'm filtering a whole branch and the node must be "matching" because it's being added as a child to the displayed node.

I believe that when I'm adding a new node, filter is for some reason not applied which nodeRenderStatus evaluates as "does not match". When I press some key, node is re-rendered and this time filter is applied and therefore is also displayed.

Environment

  • Browser type and version: FF82
  • jQuery and jQuery UI versions: 3.5.1, 1.12.1
  • Fancytree version: 2.37.0
    enabled/affected extensions:
@mar10
Copy link
Owner

mar10 commented Nov 29, 2020

Does another call to this.tree.filterBranches(node => node.data.noteId === 'XXX'); fix it for you?
In this case I would consider to a a tree.updateFilter() method, a a generic helper, that can be called after modifying operations.

@zadam
Copy link
Author

zadam commented Nov 29, 2020

Yes, calling this again after .addChildren() seems to fix the issue, I'll use that as a work around for now, thanks for that.

My only concern with this approach (assuming that .updateFilter() will just recalculate everything) is performance. I imagine that applying filter is an expensive operation on large trees, but perhaps it won't be so bad since no changes (except the addition itself) will have to be rendered.

@mar10 mar10 closed this as completed in 635e039 Nov 29, 2020
@mar10 mar10 removed the waiting label Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants