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

Update values in tree view programatically #271

Closed
henkmollema opened this issue Feb 12, 2016 · 6 comments
Closed

Update values in tree view programatically #271

henkmollema opened this issue Feb 12, 2016 · 6 comments

Comments

@henkmollema
Copy link

Perhaps this is a stupid question, but I can't figure it out: how do I reflect changes to node values I made programatically in the tree view. My use-case is a following:

When a node within a certain array is moved, I want to update a property which represents the sort order of that object programatically.

Roughly the flow:

  1. Capture the global onChange event
  2. Figure out if it's a moveNodes event and get the moved node
  3. Set the value of a child node to an integer which represents the sort order: childNode.childs[6].value = i + 1

So far, so good. But the change is not reflected in the tree view. I could just call editor.set(editor.get()); but that will cause the tree view to collapse.

This leaves me with two options:
Either use above function and expand the node again, however I could not get this working. I tried:

editor.content.removeChild(editor.table);
parentNode.expand();
editor.content.appendChild(editor.table);

Without success though..

Or update the DOM with editor.node._updateDomValue(). This would not work either.

Any advice will be greatly appreciated.

@josdejong
Copy link
Owner

Hi, this functionality is simply missing right now. You can only get/set the whole JSON object, and you can only get a notification that "something" changed but not what.

@tomalec started implementing changesets a long time ago, see #102 and #136, but that was never finished. It's still on the wishlist though :).

@henkmollema
Copy link
Author

I actually got it working using node.updateValue() 😄

Thanks anyways!

@josdejong
Copy link
Owner

Ah, ok. Great if that works for you. It's no public API so it may break some day in the future, but fine for now I think.

@mnzaki
Copy link

mnzaki commented Mar 15, 2018

For future googlers:
Here's a quick hack to maintain expanded nodes after changing the editors data: #312 (comment)

@ohabash
Copy link

ohabash commented Sep 30, 2018

@henkmollema how were you able to detect a change in the sort order? by reading here it looks like something like the following is possible... ?

onChange: function (changed) {
  if(changed === 'moveNodes'){
  	this.updateSortOrder()
  }
}

@josdejong
Copy link
Owner

@ohabash lets discuss in #583

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

4 participants