EasyUI Forum
February 13, 2025, 03:19:26 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [Solved]Checking tree leaf nodes selectively through javascript  (Read 534 times)
brucet622
Newbie
*
Posts: 8


View Profile Email
« on: January 28, 2025, 11:59:59 AM »

I have a tree that I load from the server.  I have other buttons that are used to select specific leaf nodes in the tree based upon some selection.  I'm having a few issues:

  • When I set "checked" on a node, the onCheck function is called.  It doesn't hurt anything but can be called a LOT if there are a large number of items to check.  I just disable that until I'm finished.  So far so good.
  • When a leaf is checked, the parent doesn't go to in intermediate state.  I can also check that node but it does put a check there.  Expanding the parent does expand but it still doesn't set it to intermediate.  I haven't found a way to set that manually.
  • The biggest issue is that when the code finishes, the tree is reloaded again from the host wiping out all the changes.  It seems to do this multiple times.  I don't have any explicit code that does that.  Not sure what is happening.  I've setup onBeforeLoad event to return false until we are done but that only stops the first one.  Again, not sure where they are coming from.

Before I go to the next step about filtering the data as it comes from the server based upon what things need to set, is there a better approach here?  Is there a way to stop the reload of the tree automatically?  

Hopefully someone can point me in the right direction.  Thanks in advance!

Bruce
« Last Edit: January 29, 2025, 03:53:54 PM by brucet622 » Logged
jega
Full Member
***
Posts: 211


View Profile
« Reply #1 on: January 29, 2025, 12:50:29 PM »

Hi.

Is it possible to see an example of what you have so far. I use both tree and treegrid in several projects and have no troubles at all.

"When i set checked" are you doing it after the load ? I never do that, but set it checked already in my json data. This way the onCheck is not called.

"When a leaf is checked"
Sounds like it is this sample, that works just fine.
https://www.jeasyui.com/demo/main/index.php?plugin=Tree&theme=material-teal&dir=ltr&pitem=&sort=asc

But show an example

Jesper
Logged
brucet622
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: January 29, 2025, 02:36:26 PM »

Thanks for the reply Jesper.

Let me see what I can put together for an example.  I might take the demo you pointed to and then add what I'm trying to do:

The tree gets loaded from the server and the user can then check or uncheck whatever they want.  All that works just fine.  The problem come when they have, say 100 nodes, each with a set of leaves and they want to only check one of the leaves in all the nodes.  That can take 200 clicks!  (100 to expand, 100 to click).   What I want to do is have a button that the user can select which of those they want checked (or unchecked) and have the javascript code do that for them.  Hope that makes sense....

If I do it the way I think you are suggesting, on a button press I would have to grab the contents of the tree, update it with the changes from the button, and then reload the entire tree again with this new data.  That might be the only way I can do it since none of what I've been trying to do has worked so far.  Worth a shot...

Bruce
Logged
brucet622
Newbie
*
Posts: 8


View Profile Email
« Reply #3 on: January 29, 2025, 03:53:05 PM »

OK, I think I have something that might work. 

1.  Call the getRoots method to get the data in the tree.  This will reflect any changes the user made after the initial load.
2.  Modify the array to reflect what we needed.  For example: roots[0].children[0].checked = true
3.  call the loadData method with the modified data.  This will update the tree, will set any needed states to intermediate, and most importantly NOT reload the tree from the server.

Actually manually calling the check method on the node will check the node but it also caused a reload of the tree from the server, wiping out the change.

Live and learn I guess....

Thanks!

Bruce
Logged
brucet622
Newbie
*
Posts: 8


View Profile Email
« Reply #4 on: January 31, 2025, 06:00:36 AM »

One other note to anyone else trying this...  If you have cascadeCheck on and you want to uncheck a leaf, you have to make sure the parent is also unchecked.  If not, when the data is loaded, it will recheck the leaf for you.  When the parent is unchecked and a leaf is unchecked but there could be other leaves checked, the system will know to set the parent to intermediate.  That is the only way I've figured out to actually get a parent set to intermediate correctly.

Burce
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!