如何过滤TreeGrid?

时间:2012-03-01 11:16:43

标签: filter smartgwt treegrid

我目前有TreeGrid,其中显示名称的节点。数据来自手动填充的DataSource

nodeName字段上设置过滤器时,过滤器未完成recursevily,因此我只能过滤根节点

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

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

代码

的DataSource:

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();
}

2 个答案:

答案 0 :(得分:1)

我解决了这个问题。

问题是过滤器正在调用服务器来获取数据,而我的数据源设置为仅限客户端。要解决此问题,employeeTree必须employeeTree.setLoadDataOnDemand(false);

答案 1 :(得分:0)