Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    In the following example, how can I add a new tree node into the treegrid?

    TreeGrid treeGrid = new TreeGrid();
    treeGrid.setWidth(300);
    treeGrid.setHeight(400);
    TreeGridField field = new TreeGridField("Name", "Tree from local data");
    field.setCanSort(false);
    treeGrid.setFields(new TreeGridField[]{field});
    Tree tree = new Tree();
    tree.setModelType(TreeModelType.PARENT);
    tree.setNameProperty("Name");
    tree.setIdField("EmployeeId");
    tree.setParentIdField("ReportsTo");
    tree.setShowRoot(true);
    EmployeeTreeNode root = new EmployeeTreeNode("4", "1", "Charles Madigen");
    EmployeeTreeNode node2 = new EmployeeTreeNode("188", "4", "Rogine Leger");
    EmployeeTreeNode node3 = new EmployeeTreeNode("189", "4", "Gene Porter");
    EmployeeTreeNode node4 = new EmployeeTreeNode("265", "189", "Olivier Doucet");
    EmployeeTreeNode node5 = new EmployeeTreeNode("264", "189", "Cheryl Pearson");
    tree.setData(new TreeNode[]{root, node2, node3, node4, node5});
    tree.setRoot(root);
    treeGrid.setData(tree);
    treeGrid.draw();

    How can I add a new tree node into the treegrid after the treegrid has been created?

    #2
    Have you tried the Tree.add methods?

    Comment


      #3
      Hello.
      I am using the same code as shown in showcase, and if I do instead:
      Code:
      tree.setData(new TreeNode[]{root, node2, node3, node4});
      new Timer() {
       	 @Override
            	 public void run() {
         		 treeGrid.addData(node5);
            	 }
      }.schedule(2000);
      it gives the following error:
      WARN:Log:Tree.add(): specified parent node:undef is not in the tree, returning


      So the question remains, how to add records in tree given that the records to be added have the attributes idField and parentIdField properly initialized?

      Comment


        #4
        addData() is an operation for databound TreeGrids (TreeGrids with a DataSource). If you want to add nodes to a non-databound TreeGrid, call methods on the Tree directly.

        Comment

        Working...
        X