我尝试使用带有ext表和dnd5扩展的fancytree。到目前为止,这对我来说还不错。我希望通过dnd对表列进行排序,同时也通过。将<th>内容注册为可拖放不起作用。我得到以下例外:
Uncaught TypeError: Cannot read property 'toggleClass' of null
at HTMLTableElement.<anonymous> (jquery.fancytree.dnd5.js:530)
at HTMLTableElement.dispatch (jquery.js:5183)
at HTMLTableElement.elemData.handle (jquery.js:4991)查看jquery.fancytree.dnd5.js文件,我发现CSS类。
classDragSource = "fancytree-drag-source",
classDragRemove = "fancytree-drag-remove",
classDropAccept = "fancytree-drop-accept",
classDropAfter = "fancytree-drop-after",
classDropBefore = "fancytree-drop-before",
classDropOver = "fancytree-drop-over",
classDropReject = "fancytree-drop-reject",
classDropTarget = "fancytree-drop-target",我玩过一点,但没有成功,很难分辨出相关的部分。
尽管如此,以下是HTML部分
<table id="treegrid" width="100%">
<colgroup>
<col width="50px"></col>
<col width="50px"></col>
<col width="50px"></col>
<col width="50px"></col>
<col width="50px"></col>
<col width="50px"></col>
<col width="50px"></col>
<col width="1*"></col>
<col width="1*"></col>
</colgroup>
<thead>
<!-- <tr> <th></th> <th>Filter</th>
<th><input type="text" name="FName"/></th>
<th><input type="text" name="FTeileNr"/></th>
<th><input type="text" name="FMenge"/></th> <th>AbsQty</th><th>Pos</th><th>AbsPos</th><th>Like</th> </tr>-->
<tr> <th></th>
<th><div id="tgLevel" draggable="true" class="colresizeable">Level</div></th>
<th><div id="tgName" draggable="true" class="colresizeable">Name</div></th>
<th><div id="tgTeileNr" draggable="true" class="colresizeable">TeileNr</div></th>
<th><div id="tgTMenge" draggable="true" class="colresizeable">Menge</div></th>
<th><div id="tgTAbsQty" draggable="true" class="colresizeable">AbsQty</div></th>
<th><div id="tgPos" draggable="true" class="colresizeable">Pos</div></th>
<th><div id="tgAbsPos" draggable="true" class="colresizeable">AbsPos</div></th>
<th><div id="tgLike" draggable="true" class="colresizeable">Like</div></th>
</tr>
</thead>
<!-- Otionally define a row that serves as template, when new nodes are created: -->
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="alignRight"></td>
<td class="alignRight"></td>
<td></td>
<td></td>
<td class="alignCenter">
<input type="checkbox" name="like">
</td>
</tr>
</tbody>
</table>我添加了如下的dnd5部分
dnd5: {
preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
autoExpandMS: 1000,
multiSource: true, // drag all selected nodes (plus current node)
// focusOnClick: true,
// refreshPositions: true,
dragStart: function(node, data) {
// allow dragging `node`:
data.dataTransfer.dropEffect = "move";
return true;
},
dragEnter: function(node, data) {
data.node.info("dragEnter", data);
data.dataTransfer.dropEffect = "link";
return true;
},
dragEnd: function(node, data) {
},
dragDrop: function(node, data) {
var dataTransfer = data.dataTransfer,
sourceNodes = data.otherNodeList,
event = data.originalEvent,
copyMode = event.ctrlKey || event.altKey;
if( copyMode ) {
$.each(sourceNodes, function(i, o){
o.copyTo(node, data.hitMode, function(n){
delete n.key;
n.selected = false;
n.title = "Copy of "+n.title;
if(data.hitMode=="over"){
$.when(mergerelation(node.data.ident,o.data.ident,"--")).then(console.log("back from mergecallajax"));
console.log("TNODE: "+o.title+" id:"+o.data.ident+" tpos"+"--");
console.log("SNODE: "+node.title+" id: "+node.data.ident);
}
if(data.hitMode=="after"){
var tpos=node.data.Pos;
var tnode=node.data.PartID;
n.data.pos=tpos;
$.when(mergerelation(tnode,o.data.ident,tpos)).then(console.log("back from mergecallajax"));
console.log("TNODE: "+o.title+" id:"+o.data.ident);
console.log("SNODE: "+node.title+" id: "+node.data.ident);
}
if(data.hitMode=="before"){
var tpos=node.data.Pos;
var tnode=node.data.PartID;
n.data.pos=tpos;
$.when(mergerelation(tnode,o.data.ident,tpos)).then(console.log("back from mergecallajax"));
console.log("TNODE: "+o.title+" id:"+o.data.ident);
console.log("SNODE: "+node.title+" id: "+node.data.ident);
}
});
}
});
});
} else {
$.each(sourceNodes, function(i, o){
o.moveTo(node, data.hitMode);
});
}
node.debug("drop", data);
node.setExpanded();
}
}发布于 2018-11-17 07:49:57
似乎您找到了一个bug: Fancytree尝试处理拖动事件,同时也处理不是节点的元素。
我在这里打开了一个问题:https://github.com/mar10/fancytree/issues/910
(应该很快就能修好)
https://stackoverflow.com/questions/53338682
复制相似问题