Blazorise icon indicating copy to clipboard operation
Blazorise copied to clipboard

Treeview - Expand all nodes in the TreeView by default

Open saeb-panahifar opened this issue 1 year ago • 10 comments

Is your feature request related to a problem? Please describe. It seems that there is no mechanism to expand all nodes in the TreeView by default

A clear and concise description of what the problem is. Example: I am trying to set the below Treeview expand but unfortunately, there is no specific property to configure. Screen Shot 2022-09-14 at 10 33 17 AM

Describe the solution you'd like A clear and concise description of what you want to happen. Include any alternative solutions you've considered.

Additional context

Add any other context or screenshots about the feature request here.

saeb-panahifar avatar Sep 14 '22 16:09 saeb-panahifar

Hello,

While a good feature to have.

You might be able to do this currently. Have you tried adding the Nodes to the ExpandedNodes collection? Even if its the full collection? My guess is that it can still figure out the correct structure as long as GetChildNodes and HasChildNodes are well defined.

David-Moreira avatar Sep 19 '22 21:09 David-Moreira

Here is a PR for this: https://github.com/Megabit/Blazorise/pull/4116

saeb-panahifar avatar Sep 19 '22 23:09 saeb-panahifar

Hello,

While a good feature to have.

You might be able to do this currently. Have you tried adding the Nodes to the ExpandedNodes collection? Even if its the full collection? My guess is that it can still figure out the correct structure as long as GetChildNodes and HasChildNodes are well defined.

Yes, I agree it is a useful feature. I checked that but it didn't work.

saeb-panahifar avatar Sep 19 '22 23:09 saeb-panahifar

Hello, While a good feature to have. You might be able to do this currently. Have you tried adding the Nodes to the ExpandedNodes collection? Even if its the full collection? My guess is that it can still figure out the correct structure as long as GetChildNodes and HasChildNodes are well defined.

Yes, I agree it is a useful feature. I checked that but it didn't work.

Hello, I had some treeview code sitting around from helping a customer. So I went and gave it a try since I was kinda sure it would work. It does work, here's an example.

image image image

David-Moreira avatar Sep 20 '22 20:09 David-Moreira

Let me try this way.

saeb-panahifar avatar Sep 20 '22 22:09 saeb-panahifar

Right. Just post your source code if you can if it isn't working for some reason.

David-Moreira avatar Sep 20 '22 22:09 David-Moreira

By doing this way it worked. The reason why before did not work was because I just loaded and set it to ExpandedNodes. So I already loaded the items why do we need to loop again for expanding (child nodes)?

Let me tell you the scenarios we have.

  1. We need to expand all nodes when we load data.
  2. We want to store data with IsExpanded. (In the current implementation we have to store an extra list for expanded nodes).
  3. Sometimes we want to set a specific node depending on the business logic in the backend.

All in all, If we have expanded information besides the node we can fully control of node. We won't need to store a separate list. Loaded data will have that information.

saeb-panahifar avatar Sep 20 '22 22:09 saeb-panahifar

So I already loaded the items why do we need to loop again for expanding (child nodes)?

On my version I was iterating through every node and adding every node's Children to the expanded Nodes. I.E: ByModule adds Developer / Test / Settings Which in turn loops again on each node and adds their own children.... Developer adds IDE / Tools, so on... image

If you have the IsExpanded information on your own data. Then it's easy to just add those exact nodes to the ExpandedNodes collection.

So with this, do you have enough information to make it work as you'd like on your end?

David-Moreira avatar Sep 20 '22 22:09 David-Moreira

I would prefer to have one collection rather than two but that is fine.

Thanks for the explanation.

Since your approach support this scenario. Should I close this PR? https://github.com/Megabit/Blazorise/pull/4116

saeb-panahifar avatar Sep 20 '22 23:09 saeb-panahifar

Well we'd still appreciate your contribution to Blazorise.

The ExpandAll is a good feature to have. But of course, in the end its up to you.

David-Moreira avatar Sep 21 '22 07:09 David-Moreira