At the first impression it looks like simplest task... But regardless of that I spent a couple of great hours trying to figure out how to refresh the tree control on EcoResCategory form.
The main goal was to clone a sub-tree in. The copying itself was implemented at the table level... Nothing interesting - a new record (EcoResCategory) should be initialized and inserted using addToHierarchy() method. Well done, now how to refresh the control on the form? I tried to find an appropriate method that can do it for me in the EcoResCategory form and EcoResCategoryTreeDatasource class... No luck. This way I decided that I can reinitialize the control and I called the initializeHelper() method from EcoResCategory form. Our tree has been refreshed but the selected node remains the root node that is not good for me. The plan was to re-select the my current node and I called the expandAndSelect() method from EcoResCategoryTreeDatasource class.
So, the final code sequence that I used in my form is:
The main goal was to clone a sub-tree in. The copying itself was implemented at the table level... Nothing interesting - a new record (EcoResCategory) should be initialized and inserted using addToHierarchy() method. Well done, now how to refresh the control on the form? I tried to find an appropriate method that can do it for me in the EcoResCategory form and EcoResCategoryTreeDatasource class... No luck. This way I decided that I can reinitialize the control and I called the initializeHelper() method from EcoResCategory form. Our tree has been refreshed but the selected node remains the root node that is not good for me. The plan was to re-select the my current node and I called the expandAndSelect() method from EcoResCategoryTreeDatasource class.
So, the final code sequence that I used in my form is:
int lastSelected; //Last selected node Id
int64 key; //RecId from the latest selected node
...
lastSelected = CtrlFormTree.getSelection();
key = CtrlFormTree.getItem(lastSelected).data();
element.initializeHelper();
hierarchyTree.expandAndSelect(key);
...
I would like to share this approach and in case if you have a better solution don't hesitate to provide it.
No comments:
Post a Comment