Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    TreeGrid Filter Issue

    Hello, I’m encountering an issue when trying to filter a TreeGrid using the filter editor and wanted to check if I might be doing something incorrectly.

    I'm working with a TreeGrid that doesn't have a data source, but when I attempt to filter it, I receive an error. Is a data source required for filtering a TreeGrid? If so, is there an example or recommended approach for setting up a client-only data source for a tree structure? I've attempted this but am not having much luck adding nodes to the tree after the initial setData call. Calling treeGrid.addData(node) does not seem to respect the trees hierarchy and just appends nodes to the root.

    Am I approaching this the wrong way? Any guidance would be appreciated. Thank you


    SmartClient Version: v13.0p_2024-01-20/Enterprise Deployment (built 2024-01-20)

    Chrome Version 133.0.6943.60

    Stack Trace
    Code:
    ISC_Core.js?ver=6.5.0.0-develop:323 Uncaught TypeError: Cannot read properties of null (reading 'getTreeRelationship')
        at _3.isc_ResultTree_getTreeRelationship [as getTreeRelationship] (ISC_DataBinding.js?v….0-develop:2106:152)
        at _3.isc_ResultTree_init [as init] (ISC_DataBinding.js?v…0.0-develop:2081:79)
        at _3.isc_Class_completeCreation [as completeCreation] (ISC_Core.js?ver=6.5.0.0-develop:373:6)
        at Object.isc_c_Class_create (ISC_Core.js?ver=6.5.0.0-develop:244:47)
        at _3.isc_Canvas_createResultTree [as createResultTree] (ISC_DataBinding.js?v….0-develop:2391:190)
        at _3.isc_TreeGrid_createDataModel [as createDataModel] (ISC_DataBinding.js?v….0-develop:2466:518)
        at _3.isc_Canvas_filterWithCriteria [as filterWithCriteria] (ISC_Core.js?ver=6.5.0.0-develop:4889:216)
        at _3.isc_c_Class_invokeSuper [as invokeSuper] (ISC_Core.js?ver=6.5.0.0-develop:308:93)
        at _3.isc_c_Class_Super [as Super] (ISC_Core.js?ver=6.5.0.0-develop:300:170)
        at _3.isc_ListGrid_filterWithCriteria [as filterWithCriteria] (ISC_DataBinding.js?v….0-develop:2464:241)
        at _3.isc_c_Class_invokeSuper [as invokeSuper] (ISC_Core.js?ver=6.5.0.0-develop:308:93)
        at _3.isc_c_Class_Super [as Super] (ISC_Core.js?ver=6.5.0.0-develop:300:170)
        at _3.isc_TreeGrid_filterWithCriteria [as filterWithCriteria] (ISC_DataBinding.js?v…0.0-develop:2468:13)
        at _3.isc_Canvas__filter [as $wo] (ISC_Core.js?ver=6.5.0.0-develop:4888:6)
        at _3.isc_c_Class_invokeSuper [as invokeSuper] (ISC_Core.js?ver=6.5.0.0-develop:308:93)
        at _3.isc_c_Class_Super [as Super] (ISC_Core.js?ver=6.5.0.0-develop:300:170)
        at _3.isc_ListGrid__filter [as $wo] (ISC_Grids.js?ver=6.5.0.0-develop:2484:61)
        at _3.isc_Canvas_filterData [as filterData] (ISC_Core.js?ver=6.5.0.0-develop:4836:789)
        at _3.isc_ListGrid_handleFilterEditorSubmit [as handleFilterEditorSubmit] (ISC_Grids.js?ver=6.5….0-develop:2138:370)
        at _3.isc_RecordEditor_performFilter [as performFilter] (ISC_Grids.js?ver=6.5….0-develop:3736:167)
        at Object.isc_c_Class_fireCallback [as fireCallback] (ISC_Core.js?ver=6.5.0.0-develop:323:252)
        at Object.isc_c_Class__fireActionsOnPause [as $cm] (ISC_Core.js?ver=6.5.0.0-develop:328:383)
        at _3.isc_c_Class_fireCallback [as fireCallback] (ISC_Core.js?ver=6.5.0.0-develop:323:252)
        at _3.isc_c_Timer__fireTimeout [as $in] (ISC_Core.js?ver=6.5.0.0-develop:2179:6)
        at ISC_Core.js?ver=6.5.0.0-develop:2174:40
    isc_ResultTree_getTreeRelationship @ ISC_DataBinding.js?v….5.0.0-develop:2106
    isc_ResultTree_init @ ISC_DataBinding.js?v….5.0.0-develop:2081
    isc_Class_completeCreation @ ISC_Core.js?ver=6.5.0.0-develop:373
    isc_c_Class_create @ ISC_Core.js?ver=6.5.0.0-develop:244
    isc_Canvas_createResultTree @ ISC_DataBinding.js?v….5.0.0-develop:2391
    isc_TreeGrid_createDataModel @ ISC_DataBinding.js?v….5.0.0-develop:2466
    isc_Canvas_filterWithCriteria @ ISC_Core.js?ver=6.5.0.0-develop:4889
    isc_c_Class_invokeSuper @ ISC_Core.js?ver=6.5.0.0-develop:308
    isc_c_Class_Super @ ISC_Core.js?ver=6.5.0.0-develop:300
    isc_ListGrid_filterWithCriteria @ ISC_DataBinding.js?v….5.0.0-develop:2464
    isc_c_Class_invokeSuper @ ISC_Core.js?ver=6.5.0.0-develop:308
    isc_c_Class_Super @ ISC_Core.js?ver=6.5.0.0-develop:300
    isc_TreeGrid_filterWithCriteria @ ISC_DataBinding.js?v….5.0.0-develop:2468
    isc_Canvas__filter @ ISC_Core.js?ver=6.5.0.0-develop:4888
    isc_c_Class_invokeSuper @ ISC_Core.js?ver=6.5.0.0-develop:308
    isc_c_Class_Super @ ISC_Core.js?ver=6.5.0.0-develop:300
    isc_ListGrid__filter @ ISC_Grids.js?ver=6.5.0.0-develop:2484
    isc_Canvas_filterData @ ISC_Core.js?ver=6.5.0.0-develop:4836
    isc_ListGrid_handleFilterEditorSubmit @ ISC_Grids.js?ver=6.5.0.0-develop:2138
    isc_RecordEditor_performFilter @ ISC_Grids.js?ver=6.5.0.0-develop:3736
    isc_c_Class_fireCallback @ ISC_Core.js?ver=6.5.0.0-develop:323
    isc_c_Class__fireActionsOnPause @ ISC_Core.js?ver=6.5.0.0-develop:328
    isc_c_Class_fireCallback @ ISC_Core.js?ver=6.5.0.0-develop:323
    isc_c_Timer__fireTimeout @ ISC_Core.js?ver=6.5.0.0-develop:2179
    (anonymous) @ ISC_Core.js?ver=6.5.0.0-develop:2174
    setTimeout
    isc_c_Timer_setTimeout @ ISC_Core.js?ver=6.5.0.0-develop:2174
    isc_c_Class_delayCall @ ISC_Core.js?ver=6.5.0.0-develop:324
    isc_c_Class__fireOnPause @ ISC_Core.js?ver=6.5.0.0-develop:328
    isc_c_Class_fireOnPause @ ISC_Core.js?ver=6.5.0.0-develop:325
    isc_Class_fireOnPause @ ISC_Core.js?ver=6.5.0.0-develop:404
    isc_RecordEditor_performFilter @ ISC_Grids.js?ver=6.5.0.0-develop:3736
    isc_RecordEditor_performAction @ ISC_Grids.js?ver=6.5.0.0-develop:3726
    isc_RecordEditor_cellEditEnd @ ISC_Grids.js?ver=6.5.0.0-develop:3754
    isc_ListGrid_editorKeyPress @ ISC_Grids.js?ver=6.5.0.0-develop:948
    isc_c_Class_invokeSuper @ ISC_Core.js?ver=6.5.0.0-develop:308
    isc_c_Class_Super @ ISC_Core.js?ver=6.5.0.0-develop:300
    isc_RecordEditor_editorKeyPress @ ISC_Grids.js?ver=6.5.0.0-develop:3757
    itemKeyPress @ ISC_Grids.js?ver=6.5.0.0-develop:888
    isc_DynamicForm_handleItemKeyPress @ ISC_Forms.js?ver=6.5.0.0-develop:794
    isc_FormItem__fireKeyPressHandlers @ ISC_Forms.js?ver=6.5.0.0-develop:1686
    isc_FormItem_handleKeyPress @ ISC_Forms.js?ver=6.5.0.0-develop:1677
    isc_c_Class_invokeSuper @ ISC_Core.js?ver=6.5.0.0-develop:308
    isc_c_Class_Super @ ISC_Core.js?ver=6.5.0.0-develop:300
    isc_TextItem_handleKeyPress @ ISC_Forms.js?ver=6.5.0.0-develop:2221
    isc_c_EventHandler_bubbleEvent @ ISC_Core.js?ver=6.5.0.0-develop:2555
    isc_c_EventHandler_handleKeyPress @ ISC_Core.js?ver=6.5.0.0-develop:2269
    isc_c_EventHandler__handleNativeKeyPress @ ISC_Core.js?ver=6.5.0.0-develop:2265
    isc_c_EventHandler_dispatch @ ISC_Core.js?ver=6.5.0.0-develop:2654
    eval

    Test Case

    Code:
    import com.smartgwt.client.types.TreeModelType;
    import com.smartgwt.client.widgets.Canvas;
    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;
    
    import com.google.gwt.core.client.EntryPoint;
    
    public class ParentLinkingTreeSample implements EntryPoint {
    
    
        public static final TreeNode[] employeeData = new TreeNode[] {
            new EmployeeTreeNode("4", "1", "Charles Madigen"),
            new EmployeeTreeNode("189", "4", "Gene Porter"),
            new EmployeeTreeNode("265", "189", "Olivier Doucet"),
            new EmployeeTreeNode("264", "189", "Cheryl Pearson"),
            new EmployeeTreeNode("188", "4", "Rogine Leger")
        };
    
        public void onModuleLoad() {
            Tree employeeTree = new Tree();
            employeeTree.setModelType(TreeModelType.PARENT);
            employeeTree.setIdField("EmployeeId");
            employeeTree.setParentIdField("ReportsTo");
            employeeTree.setNameProperty("Name");
            employeeTree.setRootValue(1);
            employeeTree.setData(employeeData);
    
            TreeGrid employeeTreeGrid = new TreeGrid();
            employeeTreeGrid.setWidth(500);
            employeeTreeGrid.setHeight(400);
            employeeTreeGrid.setNodeIcon("icons/16/person.png");
            employeeTreeGrid.setFolderIcon("icons/16/person.png");
            employeeTreeGrid.setShowOpenIcons(false);
            employeeTreeGrid.setShowDropIcons(false);
            employeeTreeGrid.setClosedIconSuffix("");
    
            // modified, add filter field and show filter editor
            employeeTreeGrid.setFields(new TreeGridField("Name"), new TreeGridField("ReportsTo"));
            employeeTreeGrid.setShowFilterEditor(true);
    
    
            employeeTreeGrid.setData(employeeTree);
            employeeTreeGrid.setShowSelectedIcons(true);
    
            employeeTreeGrid.getData().openAll();
    
            employeeTreeGrid.draw();
        }
    
        public static class EmployeeTreeNode extends TreeNode {
            public EmployeeTreeNode(String employeeId, String reportsTo, String name) {
                setAttribute("EmployeeId", employeeId);
                setAttribute("ReportsTo", reportsTo);
                setAttribute("Name", name);
            }
        }
    
    }
    Last edited by sdc2152; 11 Feb 2025, 08:33.

    #2
    A DataSource is required for filtering. Right now, you are setting up data correctly for a parent-linked tree, but not creating a DataSource, so it does not work.

    The docs on Tree & ResultTree how to set up a DataSource that can be viewed as a Tree - it's very straightforward, you just declare foreignKey and primaryKey.

    Comment


      #3
      Not also that tree.addNode(node) is going to add to root because you haven't supplied a parent to add to. The parent is the second param, and if not passed, the only choice is to add to root.

      Comment


        #4
        Thank you for the quick response! I set up a data source, and the error message is gone. However, when I try to filter the description field with "M", all records disappear. Am I setting up the data source correctly, or am I missing something?

        Also tried setting cacheData on the data source and calling fetchData from the treeGrid but records do not appear?

        Code:
        import com.smartgwt.client.types.TreeModelType;
        import com.smartgwt.client.widgets.Canvas;
        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;
        
        import com.google.gwt.core.client.EntryPoint;
        
        public class ParentLinkingTreeSample implements EntryPoint {
        
            public static final TreeNode[] employeeData = new TreeNode[] {
                new EmployeeTreeNode("4", "1", "Charles Madigen", "Manager"),
                new EmployeeTreeNode("189", "4", "Gene Porter", "Mid-Manager"),
                new EmployeeTreeNode("265", "189", "Olivier Doucet", "Grunt"),
                new EmployeeTreeNode("264", "189", "Cheryl Pearson", "Grunt"),
                new EmployeeTreeNode("188", "4", "Rogine Leger", "Mid-Manager")
            };
        
            public static class EmployeeTreeNode extends TreeNode {
                public EmployeeTreeNode(String employeeId, String reportsTo, String name, String description) {
                    setAttribute("EmployeeId", employeeId);
                    setAttribute("ReportsTo", reportsTo);
                    setAttribute("Name", name);
                    setAttribute("Description", description);
                }
            }
        
            public void onModuleLoad() {
        
                // modified
                DataSource ds = new DataSource();
                ds.setClientOnly(true);
        
                DataSourceIntegerField employeeIdField = new DataSourceIntegerField("EmployeeId");
                employeeIdField.setPrimaryKey(true);
        
                DataSourceIntegerField reportsToField = new DataSourceIntegerField("ReportsTo");
                reportsToField.setForeignKey("EmployeeId");
        
                DataSourceTextField nameField = new DataSourceTextField("Name");
        
                DataSourceTextField descriptionField = new DataSourceTextField("Description");
        
                ds.setFields(employeeIdField, reportsToField, nameField, descriptionField);
                //
        
                Tree employeeTree = new Tree();
                employeeTree.setDataSource(ds); // modified
                employeeTree.setModelType(TreeModelType.PARENT);
                employeeTree.setIdField("EmployeeId");
                employeeTree.setParentIdField("ReportsTo");
                employeeTree.setNameProperty("Name");
                employeeTree.setRootValue(1);
                employeeTree.setData(employeeData);
        
                TreeGrid employeeTreeGrid = new TreeGrid();
                employeeTreeGrid.setDataSource(ds); // modified
                employeeTreeGrid.setWidth(500);
                employeeTreeGrid.setHeight(400);
                employeeTreeGrid.setNodeIcon("icons/16/person.png");
                employeeTreeGrid.setFolderIcon("icons/16/person.png");
                employeeTreeGrid.setShowOpenIcons(false);
                employeeTreeGrid.setShowDropIcons(false);
                employeeTreeGrid.setClosedIconSuffix("");
        
                // modified
                employeeTreeGrid.setFields(new TreeGridField("Name"), new TreeGridField("Description"));
                employeeTreeGrid.setShowFilterEditor(true);
                employeeTreeGrid.setKeepParentsOnFilter(true);
                //
        
                employeeTreeGrid.setData(employeeTree);
                employeeTreeGrid.setShowSelectedIcons(true);
        
                employeeTreeGrid.getData().openAll();
        
                employeeTreeGrid.draw();
            }
        
        
        }

        Comment


          #5
          You didn't say what field you were filtering on. Also, read about keepParentsOnFilter and the requirements for that property - looks like you haven't set them.

          Comment

          Working...
          X