Hi,
My TreeGrid displays well when its data is set at init time, the first time - but if I update the Tree content (tree.setData(TreeNode[])) later, the treegrid is not refreshed even if I do again a treegrid.setData(tree) or treegrid.redraw().
I have a basic listgrid, when the user clicks on a row, a tree is built and the treegrid must be refreshed.
I've tested with my own data and also the static employeeData exemple to make sure data is OK.
How can I force the Tree / TreeGrid to be refreshed ? Firing a specific event ?
This is the init code
This is the method called when the user clicks on a row of the listgrid. Its prupose is to build a new Tree to display and edit
And this is the custom TreeNode class defnition
*******************************
I found the solution : strangely enough, one has to create a new instance of the Tree class, the setData(...) method is not enought.
So to have the tree grid eventually updated I had to :
1- do : new Tree(), resetting all fields (IdField, parentField)
2- do : setData(TreeNode[])
If I omit stage 1 and reuse an existing Tree instance, it won't work.
Why ?
(Using smartgwt1.2 + GWT 1.7)
My TreeGrid displays well when its data is set at init time, the first time - but if I update the Tree content (tree.setData(TreeNode[])) later, the treegrid is not refreshed even if I do again a treegrid.setData(tree) or treegrid.redraw().
I have a basic listgrid, when the user clicks on a row, a tree is built and the treegrid must be refreshed.
I've tested with my own data and also the static employeeData exemple to make sure data is OK.
How can I force the Tree / TreeGrid to be refreshed ? Firing a specific event ?
This is the init code
Code:
goalTreeGrid = new TreeGrid(); goalTreeGrid.setCanSort(false); goalTreeGrid.setCustomIconProperty("icon"); goalTreeGrid.setAnimateFolderTime(100); goalTreeGrid.setAnimateFolders(true); goalTreeGrid.setAnimateFolderSpeed(1000); goalTreeGrid.setCanEdit(true); goalTree = new Tree(); goalTree.setModelType(TreeModelType.PARENT); goalTree.setRootValue("1"); goalTree.setIdField("nodeUID"); goalTree.setParentIdField("parentUID"); goalTree.setNameProperty("Nom"); goalTree.setShowRoot(true); goalTree.setAutoOpenRoot(true); goalTree.setRoot(fakeStartRoot); // dummy root to start with before the user selects anything goalTreeGrid.setWidth(500); goalTreeGrid.setHeight100(); goalTreeGrid.setShowOpenIcons(true); goalTreeGrid.setShowDropIcons(true); goalTreeGrid.setShowConnectors(true); TreeGridField nameTreeField = new TreeGridField("Name"); nameTreeField.setCanEdit(false); TreeGridField valueTreeField = new TreeGridField("Valeur"); nameTreeField.setCanEdit(true); goalTreeGrid.setFields(nameTreeField, valueTreeField); goalTreeGrid.setData(goalTree); goalTreeGrid.addDrawHandler(new DrawHandler() { public void onDraw(DrawEvent event) { goalTree.openAll(); } });
Code:
private void feedGoalForm(Objetivo goal, ListGridRecord record) { // Loop through the Goal (Objetivo) and build the tree up int nodeUID = 0; ArrayList<TreeNode> noeuds = new ArrayList<TreeNode>(); TreeNode goalNode = new GoalTreeNode(String.valueOf(++nodeUID), "0", "Objectif", "goal"); noeuds.add(goalNode); // Utility nodes TreeNode question, facteur, metrique, methode, param; Iterator<Pregunta> itp = goal.getPreguntas().iterator(); while (itp.hasNext()) { Pregunta pregunta = itp.next(); question = new GoalTreeNode(String.valueOf(++nodeUID), goalNode .getAttribute("nodeUID"), "Question", "question"); noeuds.add(question); FactorAdaptado factorAdaptado = pregunta.getFactorAdaptado(); facteur = new GoalTreeNode(String.valueOf(++nodeUID), question .getAttribute("nodeUID"), "Facteur", "factor"); noeuds.add(facteur); Iterator<MetricaAdaptada> itma = factorAdaptado .getMetricasAdaptadas().iterator(); while (itma.hasNext()) { MetricaAdaptada metricaAdaptada = itma.next(); metrique = new GoalTreeNode(String.valueOf(++nodeUID), facteur .getAttribute("nodeUID"), "Métrique", "metric"); noeuds.add(metrique); Iterator<MetodoAdaptado> itmtha = metricaAdaptada .getMetodosAdaptados().iterator(); while (itmtha.hasNext()) { MetodoAdaptado metodoAdaptado = itmtha.next(); methode = new GoalTreeNode(String.valueOf(++nodeUID), metrique.getAttribute("nodeUID"), "Méthode", "method"); noeuds.add(methode); Iterator<ValorParametro> itvp = metodoAdaptado.getValores() .iterator(); while (itvp.hasNext()) { ValorParametro valorParametro = itvp.next(); param = new GoalTreeNode(String.valueOf(++nodeUID), methode.getAttribute("nodeUID"), "Param", "param"); noeuds.add(param); } } } } TreeNode[] nodes = new TreeNode[noeuds.size()]; goalTree.setData(noeuds.toArray(nodes)); goalTreeGrid.setData(goalTree); goalTreeGrid.redraw(); // //goalTree.setData(employeeData2); // SC.say(noeuds.toString()); }
And this is the custom TreeNode class defnition
Code:
public static class GoalTreeNode extends TreeNode { public GoalTreeNode(String nodeUID, String parentUID, String name, String type) { setAttribute("nodeUID", nodeUID); setAttribute("parentUID", parentUID); setAttribute("Nom", name); setAttribute("Type", type); setAttribute("Valeur", "vide"); if (type.equals("goal")) setAttribute("icon", "chart_organisation.png"); else if (type.equals("question")) setAttribute("icon", "question_node.gif"); else if (type.equals("factor")) setAttribute("icon", "factor_node.gif"); else if (type.equals("method")) setAttribute("icon", "method_node.gif"); else if (type.equals("metric")) setAttribute("icon", "measure_node.gif"); else if (type.equals("param")) setAttribute("icon", "parameter_node.gif"); } public String toString() { return getAttribute("Nom") + " parentUID:" + getAttribute("parentUID") + " nodeUID:" + getAttribute("nodeUID") + " type:" + getAttribute("Type") + "\n"; } }
*******************************
I found the solution : strangely enough, one has to create a new instance of the Tree class, the setData(...) method is not enought.
So to have the tree grid eventually updated I had to :
1- do : new Tree(), resetting all fields (IdField, parentField)
2- do : setData(TreeNode[])
If I omit stage 1 and reuse an existing Tree instance, it won't work.
Why ?
(Using smartgwt1.2 + GWT 1.7)
Comment