Question

I have a tree which is sorted by an order no in the node data. However, I am trying to order the nodes after drag and dropping a node in the tree. I can update the order no successfully but the node hasnt moved on the tree. It works after I drag the node again to the position.

 $("#projectIssues").jstree({
        sort: treeSortFunction,
        json_data: { data: nodes },
        ui: { "select_limit": 1 },
        themes: { url: themeUrl },
        core: { "check_callback": true },
        plugins: ["themes", "json_data", "ui", "sort", "dnd", "crrm"],
        crrm: {
            "move": {
            "default_position": "inside",
            "check_move": function(n) {
                    return Project.ViewModel.DragDropNode(n);
                }
            }
        }
    }).bind("move_node.jstree", function (e, d) {
        console.log(d.rslt.cp);
        var node = _tree._get_node(d.rslt.o);
        node.data("OrderNo", d.rslt.cp);
        console.log("Current Node Order:" + node.data("OrderNo"));
        Project.ViewModel.UpdateNodeOrder(d.rslt.np, d.rslt.o);

    }).bind("dblclick.jstree", doubleClickNode)
    .bind("select_node.jstree", function (event, result) {
        var node = result.rslt.obj;
        Project.ViewModel.UpdateEditor(node);
    });

The method that updates the order no

 self.UpdateNodeOrder = function (parentNode, curNode) {
    var childNodes = _tree._get_children(parentNode);
    var node = _tree._get_node(curNode);
    for (var i = node.data("OrderNo"); i <= childNodes.length-1; i++) {
        var n = _tree._get_node(childNodes[i]);
        if (n != undefined) {
            if (node.data("Name") !== n.data("Name")) {
                n.data("OrderNo", i + 1);
            }
            console.log(n.data("Name") + " " + n.data("OrderNo"));
        }
    }
};
Was it helpful?

Solution

Added _tree.sort(parentNode.children("ul") which did the trick

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top