Hierarchy manipulations lead to javascript error

Hello!

We’ve faced the problem during manipulations with hierarchy in the tree grid.

I’ll try to describe situation detailed below:

  1. We got some nodes (at least 4 to reproduce the bug) at the same level (for example in the root).

—Node1
—Node2
—Node3
—Node4

  1. We drag first node to second, the first becomes a child of the second

—Node1
|
|—Node2
—Node3
—Node4

  1. We repeat the same operation with 3rd and 4th nodes.

—Node1
|
|—Node2
—Node3
|
|—Node4

  1. At least we want to drag Node2 to Node3
    Screen shows notification “Contacting server…” and hangs.
    There is JS error can be seen:

  2. Browser:
    ‘this.getChildren(…)’ is null or not an object

  3. JS debug:
    this.getChildren(_5) has no properties
    in the file ISC_Grid.js - Line 98

On #1, did you mean you drag the second node to the first (you showed the reverse).

Can you show your code for this? These operations work normally in the tree drag and drop examples we provide.

Yes, you’re right, we drag second node to the first.

Examples show only dragging nodes to primordial folders and don’t allow drag a node to another node.

We have the following code (properties of treeGrid):

autoFetchData: true,
    canEdit: true,
    canReorderRecords: true,
    canReparentNodes:true,
    canDrop:true,
    canAcceptDroppedRecords: true,
    canDragRecordsOut: true,
    canDropOnLeaves:true,
    dragDataAction: "move",
    nodeIcon:"icons/company.gif",
    folderIcon:"icons/groupcompany.gif",
    showDropIcons:false,
    showOpenIcon:true,
    selectionType:"single",
    closedIconSuffix:"",
    editByCell: true,
    editEvent: "click",
    data:    isc.Tree.create({
        ID:"partsTree1",
        modelType: "parent",
        rootValue: 0,
        nameProperty: "name",
        idField: "id",
        parentIdField: "parentId",
        autoFetchData: true,
        dataSource: "mappingSpringDMI"
    }),

    fields: [
        {name: "name", title:"Name", canEdit:false,  width:200}
        /*List of other fields*/
    ],

    folderDrop : function (dragRecords, dropFolder, index) {
        var id = dragRecords[0].id;
        /*alert("dragRecords[0].id" + dragRecords[0].id +" dropFolder.parentId" + this.data.getChildren(dropFolder)[index-1].parentId + " dropFolder.id" + dropFolder.id + " index:" + index);*/
        var dropNode = "";
        if (index > 0) {
            dropNode = this.data.getChildren(dropFolder)[index - 1];
        } else {
            dropNode = dropFolder;
        }
       var isMapping = (headerLabel.getContents() == headerModeMap)
        if (!isMapping && (dragRecords[0].parentId == dropNode.id)) {
            isc.warn("Please, note! Your operation doesn't change company hierarchy.");
        } else if (id == dropNode.id /*|| isSubsidaryItself(dropNode, id) == true*/) {
            isc.warn("You can't make the company subsidiary of itself!");
        } else {
            var dropOnName = "subsidiary of " + dropNode.name;
            var isStandalone = false;
            if (dropNode.id == 0) {
                dropOnName = "stand-alone company";
                isStandalone = true;
            }
            if (isStandalone && isMapping) {
                isc.warn("You can't make stand-alone company in a mapping mode!");
            } else {
                isc.confirm("Do you really want to make " + dragRecords[0].name + " " + dropOnName + "?", function(value) {
                    up(value)
                });
                function up(value) {
                    if (value) {
                        myTree2.updateData({dragRecord :dragRecords[0].id, dragOn : dropFolder, index: index, dropNode: dropNode.id}, "myTree2.fetchData(searchTreeTwoForm.getValuesAsCriteria());myTree1.fetchData(searchTreeOneForm.getValuesAsCriteria())");

                    }
                }// end function
            }
        }//else
    }

Hello Dareha,

Support has previously pointed out problems with this code and suggested corrections:

.. and has suggested you take a different approach:

Can you please act on this advice rather than posting new questions about approaches you’ve already been told aren’t correct?

Thank you for a quick answer.
But we wouldn’t like to make all nodes folders because:

  1. We need to have two different icons for nodes and folders (as they have different business meanings)
  2. In this case we need to remake a significant part of code (we spent a lot of efforts to make this code working)

Could you please help us with this problem in our implementation (using two types of items) if it’s possible, it seems this is the last our problem with smartclient in current release.

The problem you’re currently experiencing is happening because you didn’t follow our advice before. To get past it, you should follow that advice now.

On 1), override getIcon() to return different icons for nodes vs folders.

On 2), these are minimal changes. Your existing efforts are still valid.