angular-drag-and-drop-lists
angular-drag-and-drop-lists copied to clipboard
directive inserts dropped element in the wrong place when used on a <table> element
here is my basic html:
<table>
<thead>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</thead>
<tbody
dnd-list="model.list"
>
<style scoped>
.dndDraggingSource {
display: none;
}
</style>
<tr class="dndPlaceholder">
<td colspan="4">- Drop file here -</td>
</tr>
<tr
ng-repeat="item in model.list"
dnd-draggable="item"
dnd-moved="model.list.splice($index, 1)"
dnd-effect-allowed="move"
>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>
very simple and based on the "simple list" example.
when I drop a file, the directive places the item one below where it should be. if I wanted to drag an item at index N it would place it at N+1.
Same problem here.
here is how I worked around this issue:
- change the
dnd-movedattribute on the<tr>element todnd-dragstart - give the
<tbody>element adnd-dropattribute:model.listDrop(item, index) - and that callback:
vm.listDrop = function (item, index) {
vm.list.splice(index - 1, 0, item);
$scope.$apply();
return true;
};
I was having this issue for a ul with draggable li elements, but realized I had an extra li element at the top that wasn't part of the ng-repeat, causing everything to be off by one.
In @rettgerst's html above, same is true with the table (extra tr at the top, not part of the ng-repeat).
So I think this bug may be considere user-error :(