0

我目前有一个TreeGrid显示带有名称的节点。数据来自手动填充的DataSource.

nodeName字段上设置过滤器时,过滤器不会递归完成,因此我只能过滤Root 节点

如何告诉过滤器在子节点中搜索匹配项?

PS:在下面的代码中,我有 3 个节点Root>> RunChild1如果我尝试过滤器并输入“ R ”,我会得到Rootand Run。但是如果我输入“ C ”,我会得到“没有找到结果

代码

数据源:

package murex.otk.gwt.gui.client.ui.datasource;

import java.util.List;

import murex.otk.gwt.gui.client.ui.record.TreeRecord;

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

public class ClassesDataSource extends DataSource {

    private static ClassesDataSource instance = null;

    public static ClassesDataSource getInstance() {
        if (instance == null) {
            instance = new ClassesDataSource("classesDataSource");
        }
        return instance;
    }

    private ClassesDataSource(String id) {
        setID(id);

        DataSourceTextField nodeNameField = new DataSourceTextField("nodeName");
        nodeNameField.setCanFilter(true);
        nodeNameField.setRequired(true);

        DataSourceIntegerField nodeIdField = new DataSourceIntegerField("nodeId");
        nodeIdField.setPrimaryKey(true);
        nodeIdField.setRequired(true);

        DataSourceIntegerField nodeParentField = new DataSourceIntegerField("nodeParent");
        nodeParentField.setRequired(true);
        nodeParentField.setForeignKey(id + ".nodeId");
        nodeParentField.setRootValue(0);

        setFields(nodeIdField, nodeNameField, nodeParentField);
        setClientOnly(true);
    }

    public void populateDataSource(List<String> classNames) {
        TreeRecord root = new TreeRecord("Root", 0);
        addData(root);
        TreeRecord child1 = new TreeRecord("Child1", root.getNodeId());
        addData(child1);
        TreeRecord child2 = new TreeRecord("Run", child1.getNodeId());
        addData(child2);
    }

}

主要的

public void onModuleLoad() {
    ClassesDataSource.getInstance().populateDataSource(new ArrayList<String>());
    final TreeGrid employeeTree = new TreeGrid();
    employeeTree.setHeight(350);
    employeeTree.setDataSource(ClassesDataSource.getInstance());
    employeeTree.setAutoFetchData(true);
    TreeGridField field = new TreeGridField("nodeName");
    field.setCanFilter(true);
    employeeTree.setFields(field);
    employeeTree.setShowFilterEditor(true);     
    employeeTree.setAutoFetchAsFilter(true);
    employeeTree.setFilterOnKeypress(true);
    employeeTree.draw();
}
4

2 回答 2

1

我解决了这个问题。

问题是过滤器正在调用服务器以获取数据,而我的数据源设置为Client Only。要解决这个问题,employeeTree必须有employeeTree.setLoadDataOnDemand(false);

于 2012-03-01T15:20:18.493 回答
0

您也可以使用 employeeTree.setKeepParentsOnFilter(true)

http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/widgets/tree/TreeGrid.html#setKeepParentsOnFilter(java.lang.Boolean)

于 2012-03-25T23:47:43.403 回答