Hello,
It appears that neither indexOf() or findIndex() methods work when the Tree is loaded from a DataSource. find() works just fine. The issue was observed using Chrome 39.0.2171.99 and Isomorphic SmartClient/SmartGWT Framework (v10.0p_2014-12-09/Enterprise Deployment 2014-12-09) in both development and compiled modes.
Test case:
1. BuiltinDS.java
2. test_tree.ds.xml:
3. test tree table:
Start the application and click "Check" button. find() method correctly returns a TreeNode that can't be later located by indexOf() nor findIndex(). Both calls return -1.
It appears that neither indexOf() or findIndex() methods work when the Tree is loaded from a DataSource. find() works just fine. The issue was observed using Chrome 39.0.2171.99 and Isomorphic SmartClient/SmartGWT Framework (v10.0p_2014-12-09/Enterprise Deployment 2014-12-09) in both development and compiled modes.
Test case:
1. BuiltinDS.java
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.types.TreeModelType; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VStack; import com.smartgwt.client.widgets.tree.Tree; import com.smartgwt.client.widgets.tree.TreeGrid; import com.smartgwt.client.widgets.tree.TreeGridField; import com.smartgwt.client.widgets.tree.TreeNode; /** * Entry point classes define <code>onModuleLoad()</code>. */ public class BuiltInDS implements EntryPoint { private ListGrid boundList; /** * This is the entry point method. */ public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new PageKeyHandler() { public void execute(String keyName) { SC.showConsole(); } }); VStack vStack = new VStack(); vStack.setLeft(175); vStack.setTop(75); vStack.setWidth("70%"); vStack.setMembersMargin(20); final TreeGrid employeeTreeGrid = new TreeGrid(); employeeTreeGrid.setWidth(500); employeeTreeGrid.setHeight(400); employeeTreeGrid.setFields(new TreeGridField("nodeTitle")); employeeTreeGrid.setDataSource(DataSource.get("test_tree")); employeeTreeGrid.fetchData(); vStack.addMember(employeeTreeGrid); HLayout hLayout = new HLayout(10); hLayout.setMembersMargin(10); hLayout.setHeight(22); IButton button = new IButton("Check"); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { for (TreeNode tnode : employeeTreeGrid.getData().getAllNodes()) { SC.logWarn("Path:" + employeeTreeGrid.getData().getPath(tnode)); } TreeNode node = employeeTreeGrid.getData().find("/1/2"); if (node != null) { int index = employeeTreeGrid.getData().indexOf(node); int findIndex = employeeTreeGrid.getData().findIndex("id", node.getAttribute("id")); SC.say("indexOf returned " + index + " findIndex returned " + findIndex); } } }); hLayout.addMember(button); vStack.addMember(hLayout); vStack.draw(); } }
Code:
<DataSource ID="test_tree" serverType="sql" tableName="test_tree" > <fields> <field name="id" type="integer" primaryKey="true" required="true"/> <field name="nodeTitle" type="text"/> <field name="parent_id" type="integer" foreignKey=".id"/> </fields> </DataSource>
Code:
CREATE CACHED TABLE PUBLIC.TEST_TREE(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL,nodeTitle VARCHAR_IGNORECASE(255),parent_id INTEGER DEFAULT NULL) insert INTO TEST_TREE VALUES(default,'Root', null) insert INTO TEST_TREE VALUES(default,'first level', 1) insert INTO TEST_TREE VALUES(default,'second level', 2) insert INTO TEST_TREE VALUES(default,'first level-2', 1)
Comment