arilotta Posted June 6, 2017 Share Posted June 6, 2017 Hi, I know it is possible to fully expand/collapse a UniDBTreeGrid. What I'm trying to achieve is to only expand the branch that contains the selected record. Looking at Sencha documentation, it seems there is the "expand" method, so I've tried something like this: UniDBTreeGrid1.JSInterface.JSCall('expand', ['key id', true]); Unfortunately, it doesn't work. Any ideas ? Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted June 6, 2017 Administrators Share Posted June 6, 2017 Pls try FullExpand and FullCollapse methods. Quote Link to comment Share on other sites More sharing options...
arilotta Posted June 6, 2017 Author Share Posted June 6, 2017 Yes, they work, but I would like to expand only the branch with the selected record, not the whole tree. Thanks Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted June 6, 2017 Administrators Share Posted June 6, 2017 type THUniDBTreeGrid = class(TUniDBTreeGrid); procedure TMainForm.UniButton2Click(Sender: TObject); var JSStore : TJSObject; RNo : Integer; begin JSStore := (UniDBTreeGrid2 as IUniJSObjects).JSObjects.Objects['store']; RNo := THUniDBTreeGrid(UniDBTreeGrid2).RecordNo; with UniDBTreeGrid2.JSInterface do begin JSCode('var node='#1'.getNodeById('+IntToStr(RNo)+');', JSStore); JSCallGlobal('if(node)node.expand', [True]); end; end; Above code works when TreeGrid rows have Parent/Child relation. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2017 Share Posted June 6, 2017 Hi, Also you can try to use this approach: 1. UniDBTreeGrid1 -> function beforeInit(sender, config) { var me = sender; me.expandSelectedNode = function() { var _selection = me.getSelectionModel().getSelection()[0]; if (_selection) { var _expanded = _selection.get('expanded'); if (!_expanded) { me.expandNode(_selection); } } }; } 2. procedure TMainForm.UniButton1Click(Sender: TObject); begin UniDBTreeGrid1.JSInterface.JSCall('expandSelectedNode', []); end; Best regards, Quote Link to comment Share on other sites More sharing options...
arilotta Posted June 7, 2017 Author Share Posted June 7, 2017 Hi, I've tried the 2nd solution, and it works, but I would like to expand the branch all the way up starting from the selected node.The supplied code expands just the selected node. I've tried somethign like this, trying to get the parent node, and expand it, but it didn't work: function beforeInit(sender, config){ var me = sender; me.expandSelectedNode = function() { var _selection = me.getSelectionModel().getSelection()[0]; if (_selection) { var _parent = _selection.get('parentNode'); if(_parent) { _parent.set('expanded', 'true'); }; }; };} Quote Link to comment Share on other sites More sharing options...
arilotta Posted June 7, 2017 Author Share Posted June 7, 2017 In other words, I would like to achieve something like the VCL TTreeNode.MakeVisible method. Thanks Andrea Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 7, 2017 Share Posted June 7, 2017 Hi, but I would like to expand the branch all the way up starting from the selected node.The supplied code expands just the selected node. Can you try this ?: function beforeInit(sender, config) { var me = sender; me.expandSelectedNode = function() { var _selection = me.getSelectionModel().getSelection()[0]; if (_selection) { _selection.cascadeBy(function(node) { node.expand(); }) } }; } Best regards, Quote Link to comment Share on other sites More sharing options...
arilotta Posted June 8, 2017 Author Share Posted June 8, 2017 Thank you, your solution fully expands a branch from a starting node, but I need to go up the tree and expand the parents rather than the children. On the Sencha documentation, I found the function "bubble" that should do the trick. Unfortunately, if I substitute "cascadeBy" with "bubble" and an hidden node is selected, it doesn't work. Let me explain a bit more my problem. I have a hierarchical query bound to a TUniDbTreeGrid; when I open the form the tree is fully collapsed; then I change the active record on the query by code using a Locate. If the new active record is not on the root level, and it is a child, and the tree is collapsed, I need that node to be expanded, in order to have the selection visible. I really appreciate the time you are spending with me. Thanks Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 11, 2017 Share Posted June 11, 2017 Hi, It should work, can you make a simple testcase for this ?! Best regards, Quote Link to comment Share on other sites More sharing options...
arilotta Posted June 13, 2017 Author Share Posted June 13, 2017 Hi, I know it seems ridicolous, but I can't figure out how to attach a file to a post ... Andrea Quote Link to comment Share on other sites More sharing options...
arilotta Posted June 15, 2017 Author Share Posted June 15, 2017 Hi Delphi Dev, please let me know how to attach the test case, I can't see the option in the forum... Thanks Andrea Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 15, 2017 Share Posted June 15, 2017 Hi, This option is only available for subscribers. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 15, 2017 Share Posted June 15, 2017 At the moment, you can use external resources for sharing I guess... Quote Link to comment Share on other sites More sharing options...
arilotta Posted June 15, 2017 Author Share Posted June 15, 2017 Ok, I shared the tets case on Google Drive. Please download the test case from the following link: https://drive.google.com/open?id=0BweO-SJUx1wacVNYR01ma0I2S0E Steps to reproduce the issue: 1. Click "1. Fill dataset" to populate the dataset 2. Click "2. Locate root" to move the active record to the root 3. Click "Expand Selected Node" to expand it --> it works 4. Click "FullCollapse" 5. Click "3. Locate Child1" to move the active record to Child1 6. Click "Expand Selected Node" to expand it --> doesn't work, nothing happens Repeat steps 4..6 changing the node to locate, locating GrandChild1 and then GrandChil3: same behaviour the node is not made visible. If I change "cascadeBy" with "bubble", strangely, the behaviour is the same. Thank you Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 16, 2017 Share Posted June 16, 2017 Hi, Can you try this approach for now ?!: 1. MainForm -> Script: Ext.tree.Panel.addMembers({ selectPathById: function(id){ var me = this, node = me.getStore().getNodeById(id); if(node){ me.selectPath(node.getPath()); } } }); 2. and use, for example: procedure TMainForm.UniButton3Click(Sender: TObject); begin CDS.Locate('id', 2, []); //GRD.JSInterface.JSCall('expandSelectedNode', []); GRD.JSInterface.JSCall('selectPathById', [2-1]); end; ... Best regards, Quote Link to comment Share on other sites More sharing options...
arilotta Posted June 20, 2017 Author Share Posted June 20, 2017 Thank you Delphi Dev, it works using the "selectPathById" function. It is necessary to know in advance the node ID, and it is somehow tricky to get that value. However I managed to get that value directly from the query (using Oracle). For anyone that's interested in, the node index ranges from zero to N-1 (number of nodes minus 1). The first root node gets a 0 index, the second root node a 1 index, ... The first node at level 1 (child of a root node) gets a J index, given J the number of root nodes, and so on Maybe clearer with an example: N1 Index 0 N11 Index 3 N12 Index 4 N2 Index 1 N21 Index 5 N22 Index 6 N3 Index 2 N31 Index 7 N311 Index 9 N312 Index 10 N32 Index 8 Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted February 2, 2018 Share Posted February 2, 2018 Thank you Delphi Dev, it works using the "selectPathById" function. It is necessary to know in advance the node ID, and it is somehow tricky to get that value. However I managed to get that value directly from the query (using Oracle). For anyone that's interested in, the node index ranges from zero to N-1 (number of nodes minus 1). The first root node gets a 0 index, the second root node a 1 index, ... The first node at level 1 (child of a root node) gets a J index, given J the number of root nodes, and so on Maybe clearer with an example: N1 Index 0 N11 Index 3 N12 Index 4 N2 Index 1 N21 Index 5 N22 Index 6 N3 Index 2 N31 Index 7 N311 Index 9 N312 Index 10 N32 Index 8 Solution : Re build your UnitreeView by sorting your Dataset : Order by AbsoluteIndex (This is Jscript problem. Not unigui) http://forums.unigui.com/index.php?/topic/9793-treeview-order/&do=findComment&comment=51912 Quote Link to comment 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.