Drag Drop with XML DataSource not working in SmartGWT

I am using an example:

http://www.smartclient.com/smartgwt/showcase/#tree_interaction_drag_nodes

but changed datasource to XML file and now it doesn't work.

XML used:

<RootNode>
<ChildNode>
    <ChildID>2</ChildID>
    <Name>ChildNode1</Name>
    <ReportsTo>1</ReportsTo>
</ChildNode>
<ChildNode>
    <ChildID>3</ChildID>
    <Name>ChildNode1.1</Name>
    <ReportsTo>2</ReportsTo>
</ChildNode>
<ChildNode>
    <ChildID>4</ChildID>
    <Name>ChildNode2</Name>
    <ReportsTo>1</ReportsTo>
</ChildNode>
<ChildNode>
    <ChildID>5</ChildID>
    <Name>ChildNode2.1</Name>
    <ReportsTo>4</ReportsTo>
</ChildNode>
<ChildNode>
    <ChildID>6</ChildID>
    <Name>ChildNode2.1.1</Name>
    <ReportsTo>5</ReportsTo>
</ChildNode>
</RootNode>

      

whereas for grid1 and grid2 I change datasources to xml file like this:
Instead of:

grid1.setData(grid1Tree);  
grid1.getData().openAll(); 

      

I use:

    grid1.setAutoFetchData(true);  
    grid1.setDataSource(EmployeeXmlDS.getInstance());    
    grid1.draw();

      

And similarly for grid2. And here is the EmployeeXmlDS implementation:

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;


public class EmployeeXmlDS extends DataSource {

    private static EmployeeXmlDS instance = null;

    public static EmployeeXmlDS getInstance() {
        if (instance == null) {
            instance = new EmployeeXmlDS("employeesDS");
        }
        return instance;
    }

    public EmployeeXmlDS(String id) {

        setID(id);
        setTitleField("Name");
        setRecordXPath("/RootNode/ChildNode");
        DataSourceTextField nameField = new DataSourceTextField("Name", "Name", 128);
        DataSourceIntegerField childIdField = new DataSourceIntegerField("ChildID", "Child ID");
        childIdField.setPrimaryKey(true);
        childIdField.setRequired(true);
        DataSourceIntegerField reportsToField = new DataSourceIntegerField("ReportsTo", "Parent");
        reportsToField.setRequired(true);
        reportsToField.setForeignKey(id + ".ChildID");
        reportsToField.setRootValue("1");
        setFields(nameField,childIdField,reportsToField);
        setDataURL("ds/test_data/tree2.xml");
        setClientOnly(true);
    }
}

      

Please, help.

+2


source to share





All Articles