Announcement

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

    SelectItem and setDataProperties

    Hello dear developers.
    I upload data from the server in this form....
    Code:
        "title": "Project DEMO",
        "node": "project",
        "@id": "6192",
        "@p_id": "0",
        "children": [
            {
                "title": "course template micro slides - L/R",
                "node": "course",
                "@id": "17519",
                "@p_id": "6192",
                "children": [
                    {
                        "title": "1. Chapter Micro slides",
                        "node": "unit",
                        "@id": "17764",
                        "@p_id": "17519",
                        "children": [
    here @id and @p_id are unique keys for tree nodes and their parents.
    For simple TreeGrid I use this code
    Code:
            Tree courseTree = new Tree();
            courseTree.setIdField(CONSTANT._ID);
            courseTree.setParentIdField(CONSTANT._PID);
    
            TreeGrid courseTreeGrid= new TreeGrid(object);
            courseTreeGrid.setKeepParentsOnFilter(true);
            courseTreeGrid.setDataProperties(courseTree);
    and it works great.

    Now I decided to use the same thing in SelectItem and it doesn't work. I see an empty list for selection.
    Code:
            ListGridField titleField = new ListGridField(CONSTANT.TITLE);
    
            JavaScriptObject object = JavaScriptObject.createObject();
            JSOHelper.setAttribute(object, "fireItemClickForFolders", true);
    
            Tree courseTree = new Tree();
            courseTree.setIdField(CONSTANT._ID);
            courseTree.setParentIdField(CONSTANT._PID);
    
            TreeGrid courseListProperties = new TreeGrid(object);
            courseListProperties.setKeepParentsOnFilter(true);
            courseListProperties.setDataProperties(courseTree);
    
            selectedCourse = new SelectItem();
            selectedCourse.setName("selectedCourse");
            selectedCourse.setWidth(300);
            selectedCourse.setPickListWidth(400);
            selectedCourse.setHoverWidth(400);
            selectedCourse.setDataSetType("tree");
            selectedCourse.setPickListProperties(courseListProperties);
            selectedCourse.setShowTitle(false);
            selectedCourse.setValueField(CONSTANT._ID);
            selectedCourse.setDisplayField(CONSTANT.TITLE);
            selectedCourse.setPickListFields(titleField);
            selectedCourse.setMultiple(false);
            selectedCourse.setAllowEmptyValue(false);
            selectedCourse.setAddUnknownValues(false);
            selectedCourse.setAutoFetchData(false);
            selectedCourse.setOptionDataSource(projectTreeData);
            selectedCourse.setAutoOpenTree("all");
    I have to go through all the nodes in the tree and perform the following attribute assignments.
    And refuse a line of code
    courseListProperties.setDataProperties(courseTree);

    Code:
        private void setProjectNodesProperties(Record[] records, String chProperty, String dbName) {
            for (Record record : records) {
                String id = record.getAttribute(CONSTANT._ID);
                record.setAttribute("id", id);
                id = record.getAttribute(CONSTANT._PID);
                record.setAttribute("parentId", id);
                Record[] childs = record.getAttributeAsRecordArray(chProperty);
                if(childs != null && childs.length > 0) {
                    setProjectNodesProperties(childs, chProperty, dbName);
                }
            }
        }
    How do I avoid this and make setDataProperties work?

    Version v12.1p_2020-04-03
    Last edited by Hirn; 10 Apr 2020, 01:48.

    #2
    This should work via a call to item.setDataSetType("tree") - please compare your implementation to this sample.
    Last edited by Isomorphic; 10 Apr 2020, 01:58.

    Comment


      #3
      Originally posted by Isomorphic View Post
      This should work via a call to item.setDataSetType("tree")
      If you noticed, I have this line in my code.
      When debugging, I noticed that in principle the correct ResultTree is created, but data is not loaded into it for some reason.
      I tried calling fetchData in different places and at different times, but ResultTree always remains empty if I have a string

      courseListProperties.setDataProperties(courseTree);

      without it, ResultTree is filled with data and everything works, but as I wrote, I have to assign the "id" and "parentId" attributes to each node in the tree.
      You can say that this is not necessary, the tree will be displayed without assigning "id" and "parentId", but then when filtering the tree data , it is displayed in a simple list. What I need is a tree, and a filtered one at that.

      Comment

      Working...
      X