Ad

Can't Sort Nodes With ExtDnd5, Only Set As Child

I want to use FancyTree with the table and dnd5 extensions. But when I drag a node, I can only drop it in another node, not between two nodes, on the same depth level.

I tried to compare my code to the examples, but cannot find any differences. Here is my Code:

HTML Table Markup. The table- classes are for Bootstrap. The @Model.TableId is for MVC5 Razor. Both, should be irrelevant and the problem still exists, when I remove the Bootstrap classes.

<table class="treeTableControl table table-bordered table-striped table-hover" id="[email protected]">
        <colgroup>
            <col width="30px" />
            <col width="30px" />
            <col width="*" />
        </colgroup>
        <thead>
            <tr>
                <th> </th>
                <th>#</th>
                <th>Name</th>
            </tr>
        </thead> 
        <tbody>
        </tbody>
    </table>

JavaScript

init() {
        var me = this;

        me.tableid = me.$tree.data("tableid");
        me.treeTableData = CSB32["treeTableData_" + me.tableid];

        me.$tree.fancytree({
            checkbox: true,
            titleTabbable: true,
            source: me.treeTableData,
            extensions: ["table", "gridnav", "dnd5", "edit"],
            table: {
                checkboxColumnIdx: 0,
                nodeColumnIdx: 2
            },
            renderColumns: function (event, data) {
                var node = data.node;
                var $tdList = $(node.tr).find(">td");

                $tdList.eq(1)
                    .text(node.getIndexHier())
                    .addClass("alignRight");
            },
            dnd5: {
                preventVoidMoves: false,
                preventRecursion: true,
                autoExpandMS: 400,
                dragStart: function (node, data) {
                    return true;
                },
                dragEnter: function (node, data) {
                    return true;
                },
                dragDrop: function (node, data) {
                    data.otherNode.moveTo(node, data.hitMode);
                }
            },
            edit: {
                triggerStart: ["f2", "dblclick"],
                close: function (event, data) {
                    if (data.save && data.isNew) {
                        me.$tree.trigger("nodeCommand", { cmd: "addSibling" });
                    }
                }
            }
        });
    }

My example source data

{"children":[{"key":1000010,"title":"TG 628s 4-Port ETH Switch ","children":[]},
{"key":1000008,"title":"4400 Series WLAN Controller","children":[
 {"key":1000009,"title":"CISCO 3845","children":[]},
 {"key":1000007,"title":"10/100/1000Base-T LX","children":[]}]},
{"key":1000011,"title":"Test Product","children":[]}],"columns":[]}

Here I try to move #3 between #1 and #2, but I can only add the node as child

Ad

Answer

Okay, I found the mistake when trying to create a JSFiddle. My jQuery version was just too old. With 3.x I can sort the nodes as I wish.

Ad
source: stackoverflow.com
Ad