无法使用ExtDnd5对节点排序,仅设置为子节点

时间:2019-07-01 08:00:37

标签: javascript html sorting drag-and-drop fancytree

我想将FancyTree与表和dnd5扩展一起使用。但是,当我拖动一个节点时,只能将它放在同一深度级别的另一个节点中,而不是两个节点之间。

我试图将我的代码与示例进行比较,但是找不到任何区别。这是我的代码:

HTML表标记。 表类适用于Bootstrap。 @ Model.TableId用于MVC5剃刀。 当我删除Bootstrap类时,两者都应该无关紧要,并且问题仍然存在。

<table class="treeTableControl table table-bordered table-striped table-hover" id="treetable_@Model.TableId">
        <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" });
                    }
                }
            }
        });
    }

我的示例源数据

{"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

1 个答案:

答案 0 :(得分:0)

好的,我在尝试创建JSFiddle时发现了错误。我的jQuery版本太旧了。使用3.x,我可以根据需要对节点进行排序。