Standard for updating Tree components

Is there a standard for updating Perspective Tree components with data in the database?

I'm working on a Perspective tree that allows the user to track and update an organizational tree stored in the database. The UI lets the user add items to the tree by sending INSERT queries to the database, then once the update is complete, the binding on the Tree's data is refreshed. The binding fires a sproc that makes the database assign the items property on the tree with the most recent version of the tree's data in the database, including the changes made by the user.

However, this system is flawed because the records cannot track whether the records in the tree should be expanded or not. This means that any time the binding refreshes, the tree collapses or expands regardless of the state the user had it in.

Is there a way to update my tree that preserves the expanded state of each node set by the user in the current session?

It can be done by keeping a mapping of current expansion information in a separate mapping object, and referencing it in a transform on the query binding. Use a change event on the tree items to copy to the separate map.

Interesting. So there would be a whole extra json structure just to track which nodes should and shouldn't be expanded?

Would this be considered a typical solution?

Some form of it would be typical. Expansion is "state" for the client session that the DB doesn't have. It needs to be stored somewhere to avoid being blown away.

It doesn't have to, and probably shouldn't, be a complete copy of the tree's items. Just some ID and the boolean for each expandable row. (I would definitely do this part with my Integration Toolkit.)

2 Likes