ohad Posted August 22, 2021 Share Posted August 22, 2021 Hi, I populate a tree view from database using jquery and ajax. the next phase I want is to expand a scpecific parentId. Here is my code: <div class="col md-2" id="treeview_json"> </div> $(document).ready(function() { var pageURL = $(location).attr("href"); var url = '/path/to/fill_sidebar.php'; $.ajax ({ type: "GET", url: url, dataType: "json", success: function(data) { var parent_node_id; var onTreeNodeSelected = function (e, node) { GetNodeData(node.link, node.tags) } $('#treeview_json').treeview ({ data: data, backColor: 'white', expandIcon: 'fa fa-plus fa-fw', collapseIcon: 'fa fa-minus fa-fw', showBorder: false, enableLinks: true, onNodeSelected: onTreeNodeSelected, }); }, error: function(response) { alert(response.errorMsg); } }); }); I want to get a specific parentId of a node and after filling the treeview, i want to expand it something like $('#treeview_json').treeview('expandNode', [node.parentId]); Can anyone explain to me how can I do that? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/313587-expand-parent-node-after-populating-a-treeview/ Share on other sites More sharing options...
kicken Posted August 22, 2021 Share Posted August 22, 2021 2 hours ago, ohad said: Can anyone explain to me how can I do that? You need to read the documentation for whatever tree view library you are using and figure it out. There is no standard tree view widget so there's no standard way to do what you want. If you can't figure it out from the documentation, then at the very least you need to specify which library you are using to get help with it. Quote Link to comment https://forums.phpfreaks.com/topic/313587-expand-parent-node-after-populating-a-treeview/#findComment-1589291 Share on other sites More sharing options...
ohad Posted August 22, 2021 Author Share Posted August 22, 2021 Hi, Thanks for the clarification. I tried look at the documentation, and I didn't find. Its bootstrap-treeview version 1.2.0 of Jonathan Miles. https://github.com/jonmiles/bootstrap-treeview Quote Link to comment https://forums.phpfreaks.com/topic/313587-expand-parent-node-after-populating-a-treeview/#findComment-1589292 Share on other sites More sharing options...
requinix Posted August 22, 2021 Share Posted August 22, 2021 7 hours ago, ohad said: something like $('#treeview_json').treeview('expandNode', [node.parentId]); Can anyone explain to me how can I do that? It's weird you mention that because the very same documentation you couldn't find says that's exactly what you're supposed to do. Could it be that your question isn't so much "how" but rather "why does this method call not work"? Where are you putting that code? Where did "node" get defined? Any errors in the browser's console? Quote Link to comment https://forums.phpfreaks.com/topic/313587-expand-parent-node-after-populating-a-treeview/#findComment-1589294 Share on other sites More sharing options...
ohad Posted August 22, 2021 Author Share Posted August 22, 2021 I saw in the documentary how to expand a node. My problem is that I don't know which event should trigger the expanding. I need an event like onNodeSelected that call a function that do that expansion. The node will be defined under that function I hope i explained myself better Thank you Quote Link to comment https://forums.phpfreaks.com/topic/313587-expand-parent-node-after-populating-a-treeview/#findComment-1589295 Share on other sites More sharing options...
requinix Posted August 22, 2021 Share Posted August 22, 2021 I thought you said that you wanted to expand a node after filling in the tree. That isn't an event: you have code to fill in the tree so add a bit of code after that happens to expand the node. Quote Link to comment https://forums.phpfreaks.com/topic/313587-expand-parent-node-after-populating-a-treeview/#findComment-1589296 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.